zumpoof
asked on
GD/Image Magick/ Perlmagick - how do I determine the dimensions of annotated text?
I'm using perlmagick to create logos from user submitted text. The problem I'm having is that I can't predict what the image dimensions should be - some fonts end up creating text that's twice as long as others while using the same point size. This causes the text to get cutoff in some situations.
Is there any way to determine how "big" the text is, then set the size of the image based on that?
Thanks!
Zumpoof
Is there any way to determine how "big" the text is, then set the size of the image based on that?
Thanks!
Zumpoof
$image = Image::Magick->new;
$image->Set(size=>'500x100');
$image->ReadImage('xc:transparent');
$image->Annotate(gravity=>'center',font=>'myfont.ttf',pointsize=>'80',fill=>'red', text=>'ACME',antialias=>'true');
ASKER
Thanks for the comment Adam314. It looks like I may have something wrong w/ my install; I can't get QueryFontMetrics to return anything no matter what I do. Even this returns nothing:
$image->QueryFontMetrics(t ext=>'this is test', font=>'courier', pointsize=>10);
I'm digging into this and I'll let you know what I find..
$image->QueryFontMetrics(t
I'm digging into this and I'll let you know what I find..
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Adam314,
It looks like I'm going to have to re-install GD. The 'QueryFontMetrics' method is still returning null. I dug deeper and for some reason I can't access any default fonts. For example I can't just use 'courier' as a font option. If it's ok w/ you I'll accept your answer to get you the points, and I'll ask a new question to debug my default fonts issue. Sound ok?
Thanks,
Zumpoof
It looks like I'm going to have to re-install GD. The 'QueryFontMetrics' method is still returning null. I dug deeper and for some reason I can't access any default fonts. For example I can't just use 'courier' as a font option. If it's ok w/ you I'll accept your answer to get you the points, and I'll ask a new question to debug my default fonts issue. Sound ok?
Thanks,
Zumpoof
That's fine.
Open in new window