Forum Moderators: coopster

Message Too Old, No Replies

Trimming images with GD

         

Nutter

1:03 pm on Dec 21, 2006 (gmt 0)

10+ Year Member



I'm working on a script that makes an image of all the characters in a font file. To get the dimensions I'm using imagettfbbox() of each string (abcde... etc). The max width of each string becomes the width of the destination image and the sum of heights becomes the new heights.

My problem is that imagettfbbox() doesn't always seem to get the right numbers. I tried it on 5 different fonts last night and one cut off the right edge and one cut off the top.

What I'd like to do, aside from figure out how to always get the right widths and heights, is create an image that's large enough to not worry about the overlap and then trim it down like the Photoshop trim command does.

Is there a way to do this? I know I could shell to ImageMagick, but I'd prefer to use GD if possible.

coopster

3:38 pm on Dec 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



imagettfbbox gives the bounding box of text using TrueType fonts. If the font you are using isn't TT, perhaps that is why you are being returned unexpected values.

Nutter

4:05 pm on Dec 22, 2006 (gmt 0)

10+ Year Member



I don't know how imagettfbbox works, but is it possible that it's reading the information from the font file directly (widths, glyphs, etc) and estimating off of that rathat than really getting the dimensions of what an "A" should be?

Either way, I wound up using ImageMagick convert -trim to make the images and them load them in to a temp variable using GD and append them all together. And it works, so that's what's important :)