characters cutoff

firebus - June 28, 2006 - 17:44
Project:Textimage
Version:6.x-2.x-dev
Component:Miscellaneous
Category:bug report
Priority:normal
Assigned:Unassigned
Status:postponed
Description

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.

#1

reb00tz - August 16, 2006 - 07:58

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

stefano73 - August 16, 2006 - 22:40

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

danielb - February 22, 2009 - 11:11

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

danielb - February 22, 2009 - 11:24

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

Deciphered - February 22, 2009 - 21:10
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

danielb - February 23, 2009 - 01:16

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

Deciphered - February 23, 2009 - 01:18

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

Deciphered - April 21, 2009 - 03:38

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

Deciphered - April 24, 2009 - 04:44
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

Deciphered - April 26, 2009 - 23:34
Status:active» fixed

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

#11

System Message - May 10, 2009 - 23:40
Status:fixed» closed

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

#12

Alexander Ufimtsev - September 2, 2009 - 23:59
Status:closed» 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

mani.atico - September 19, 2009 - 02:10

subscribe

#14

Deciphered - September 21, 2009 - 01:56
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

danielb - September 21, 2009 - 05:53

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

#16

crosputni - October 16, 2009 - 22:28

subscribing

#17

crosputni - October 17, 2009 - 02:26

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

Herkimer - November 3, 2009 - 00:17

Thanks, Alexander Ufimtsev!

#1 worked perfectly for me.

 
 

Drupal is a registered trademark of Dries Buytaert.