Project:Textimage
Version:6.x-2.x-dev
Component:Miscellaneous
Category:bug report
Priority:normal
Assigned:Unassigned
Status:postponed

Issue Summary

with default font (no freetype), the characters can be wider than the image - resulting in cut off or even invisible characters.

this happens sometimes when textimage chooses to use 5 characters, and always with 6 characters.

there should be a control to select how many max chars textimage uses.

textimage should prevent characters from getting cut off.

Comments

#1

I had this same issue, and decided to "fix it" myself. Edit the lines #354 and #355 from:

      $imageWidth = 60 + drupal_strlen($string)*$charSpacingMax*.35;
      $imageHeight = 30 + $charJiggleAmount;

to:

      $imageWidth = 80 + drupal_strlen($string)*$charSpacingMax*.35;
      $imageHeight = 45 + $charJiggleAmount;

With the same default settings, the box does not appear to big... But the developers need to fix this instead of relying on this "hack" though!

#2

I had the same problems. I made some changes to the module, fixing several bugs I had on my system, mostly related to the foreground color and noise color not properly set. I set the noise color to the foreground color, and it showed very well on all the tests I made (using built-in fonts, TTF fonts and background images).
The attachment is the patch to my current textimage.module, it was made against the latest cvs version.

AttachmentSize
textimage.patch_1.txt 23.82 KB

#3

I am still experiencing 'cutoff' text problems with the DRUPAL 6 version - I would love to be able to configure the mathematical calculation of the width/height via the GUI

#4

PS anyone wanting a manual hack for Drupal 6

around line 677 find this:

  $bbox = imagettfbbox($fontsize, $q_angle, $font, $text);

add this afterwards:

  $bbox[1] += 2;
  $bbox[3] += 2;

That would increase the height by 2.

If you're wondering what 1 and 3 are...

0 lower left corner, X position
1 lower left corner, Y position
2 lower right corner, X position
3 lower right corner, Y position
4 upper right corner, X position
5 upper right corner, Y position
6 upper left corner, X position
7 upper left corner, Y position

from http://au.php.net/imagettfbbox

at least give us a hook to do something like this in a module?

#5

Version:4.7.x-1.x-dev» 6.x-2.x-dev

Hi danielb,

I will look into this for you and see what I can do.
However, your temporary fix will not be the solution, as soon as you use rotation it will break.

Can you supply me with the details of your preset so I can test with it?
The biggest problem I have come across with cutoff is it is different depending on font, font size and server.

Cheers,
Deciphered.

#6

There is nothing unusual about my preset, it is left to defaults. The problem likely comes from the TTF font file itself. (it's one of these http://downloads.trendnet.com/Marketing/font/ )

It is much easier for me to add 2 pixels to textimage's calculation than it would be to fix their TTF file.

#7

Hi danielb,

I doubt it is the problem of the font. As I said, I have seen cutoff before, with fonts such as Arial. It is a problem with the PHP function and my lack of compensating for the problem.

The reason I asked for your preset wasn't that I suspected it was the cause, but merely so that I could test using the exact same preset as you are using, but as you're not using a free font it complicates matters.

While your fix of adding the 2 pixels may work for you, it will only work on 0, 90, 180 and 270 degree angles, anything else will no work correctly.

I will keep hacking away at the algorithm until I have come up with a universal solution.

Cheers,
Deciphered.

#8

Just a quick update on this issue.

I've finally had a bit of time to work on Textimage and I've already come up with a partial solution for this issue, it seems to work perfectly with textimages of angles 0, 90, 180 and 360, however it still needs a fair amount of tweaking with other angles.

I will likely post this current unfinished fix as a patch sometime today.

Cheers,
Deciphered.

#9

Title:default settings cause characters to be cut off» characters cutoff

Well it's pretty clear I didn't post the patch when I said I would.

I have been working on this issue flat out and now having a development copy that is as good as it gets and character cutoff has been reduced as much as possible due to such a broken core PHP function.

The only thing holding it back from commit is that I still need to rewrite the Fixed Width, Maximum Width and Alignment code to go with the changes that have been made.

Will get something out as soon as possible.

Cheers,
Deciphered.

#10

Status:active» fixed

Fixed and committed to HEAD, DRUPAL-6--2 and DRUPAL-5--2.

#11

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#12

Status:closed (fixed)» active

current -dev code seems to create character cutoffs below font baseline for text at 0 degrees. I think the reason is that the 5th argument of imagettftext() requires baseline font coordinate instead of absolute bottom one: http://us.php.net/manual/en/function.imagettftext.php

I made it work for me in two ways:
1) changed imagecreatetruecolor() on line 724 to the following:

<?php
  $image
= imagecreatetruecolor($image_width + 1 + $fontsize/3, $image_height + 1 + $fontsize/3);
?>
i.e. increasing the image size to 1/3rd of fonsize
2) another option that worked for me was changing imagettftext() on line 754 to
<?php
  imagettftext
($image, $fontsize, $q_angle, $x, $fontsize, $fore, $font, $text);
?>
i.e. replacing $y with $fontsize

#13

subscribe

#14

Status:active» postponed

Unfortunately there are so many issues with the imagettftext and related functions that there is no way that you will get the exact same results on different environments, so I intend to implement a configuration wizard that will be required to be run on setup and when transitioning servers to make sure the offsets will setup for the current environment.

I don't have a lot of time to dedicate to this at the moment, but that is the plan, so if anyone wants to start looking into this and submit their code as a patch I would be extremely grateful.

#15

That sounds like a smart plan - you could possibly even use it to help debug installations?

#16

subscribing

#17

My issue was that the top of the font was getting cut off. To fix it, I did a workaround similar to Alexander Ufimtsev.

On line 731, I changed this:
  imagettftext($image, $fontsize, $q_angle, $x, $y, $fore, $font, $text);
to this:
  imagettftext($image, $fontsize, $q_angle, $x, $fontsize+3, $fore, $font, $text);
where $y is replaced with $fontsize+3. The +3 added enough to compensate for the fact that my font's design extended above the cutoff allowed for with imagettftext.

This is an incredibly useful module, thank you so much!

#18

Thanks, Alexander Ufimtsev!

#1 worked perfectly for me.

#19

I solved this by adding a space after the string, like:

<?php
echo theme('textimage_image', 'preset', drupal_get_title().' ', array(), 'png', drupal_get_title(), drupal_get_title());
?>

#20

Believe me, while that trick might work for you, it's not going to work for everyone.
I have a mostly working solution that should work in most (if not all) instances. It's a little more server intensive, but it will be in 3.0 when I have some more time to dedicate to it.

Cheers,
Deciphered.

#21

No, I'm sure it wont work in every instance. I would rather call it hack than trick. But it did the trick for me and I wanted to share until a more permanent solution.

Thanks for your great module, I'm looking forward to future versions.

#22

#4 worked perfectly to me // O #4 funcionou perfeitamente pra mim

#23

While we wait for a final fix for this, I've come up with the attached hack. I followed an approach mixing #4, #12 and #14: the background box is adjusted through a couple of configurable values. We might even want to provide an UI for this in the 2.x branch.

Apply the patch, flush your presets and check if the default adjustment works for you. If not add the folllowing lines to your settings.php:

$conf['textimage_adjustment_x'] = 0;
$conf['textimage_adjustment_y'] = 0;

and just play with values until you find a working couple (remember to flush presets each time you change the configuration above).

AttachmentSize
textimage-71265-23.patch 743 bytes

#24

Ran into the same problem, but changed as follows

  // Get fixed and rotated boundry box co-ordinates.
  $bbox = _textimage_imagettfbbox($fontsize + 3, $q_angle, $font, $text);

#25

Thanks crosputni, your fix also solved the same issue that I had. I'm looking forward to a permanent fix though.

Cheers,
Nick

#26

Had another look at it, and the height is good, but the baseline is off, so I changed   $y = $box_height - $bbox[3]; to   $y = $box_height - $bbox[3] - $fontsize; and for now it's working. The font I'm using is extending a lot above and below the baseline, but it seems to work as well for text without any characters below the base line.

#27

In this approach I use UI Margin settings to offset text placement and set image dimensions. Left and Top margins are used as offset and Right and Bottom for correcting image dimensions if needed.

This is universal solution, customizable for every setting and font, also works on multisite. Hope you like it ;)

AttachmentSize
textimage-characters_cutoff.patch 2.9 KB

#28

I think the only good-working solution would be rendering text on transparent background and then cropping borders, something like this: http://stackoverflow.com/questions/1669683/crop-whitespace-from-image-in...

#29

#27 - That doesn't take into account rotation, the margins should rotate with the text. Haven't tried the patch, but that much is evident from the code.

#28 - You are in fact correct sir, that is the approach I have taken. The major downside to that approach is it is much more server intensive and much slower, but it does come up with a consistent result. The other downside is that it doesn't respect transparent characters (spaces) at the start or end of a line, nor does it respect consistent line heights, so the height of 'AAAAA' would be different to '.....'.

#30

Hello Deciphered.

My patch at #27 was suggested as temporary solution for those who would like to use some funky fonts (http://www.dafont.com/scriptina-pro.font) - it works for me. It's obvious it's not for commit, I should mention about that.

Now I see that php cannot handle dimensions correctly. I'm happy to hear that you are taking another approach to handle this. I wouldn't care about server usage since renders are cached. Correct dimensions handle would be major step forward, line heights and spaces can be calculated on the basis of some additional renders. If text is 'abc' you can also render 'Aabc', 'abc abc' and check base line and space. If I may suggest - server load is less important then characters cutoff.

#31

#27 +1

#32

What version of the module was #27 created against? It no longer applies to the dev versions.

I manually applied the code lost all text output.

#33

The current version lists this issue as fixed – at least this issue is in the changelog – the problem seems to persist though; in my case, whenever the text has no letter exceeding below the baseline (which then gets cut off incorrectly)

I should also note that the problem only occured after moving servers.

Wouldn't a possible quickfix-solution be to offer a fixed line-height / box height via the UI to at least manually pry the bounding box the desired few pixels? This would also be cool to prevent different heights of boxes for the same style (because some letters go below the baseline and some don't).