measuring string size for Annotate()
Posted: 2014-09-11T13:23:30-07:00
Is there a way to figure out if text added via Annotate() got cut off when added to a background of a fixed size? Alternatively is there a way to figure out how much room will be needed for text? I have something like the following but in some cases the string stored in $names is too big and I either need to automatically adjust the font size or at least log a warning at the program output.
Thanks
-Dan
Thanks
-Dan
Code: Select all
my $text_back = Image::Magick->new();
my $x = $text_back->ReadImage('xc:white');
warn "$x" if "$x";
my $my_h = 150;
my $my_w = 600;
print "[$my_w x $my_h] ...";
$text_back->Resize(width=>$my_w, height=>$my_h);
# code here to read $names out of a file. It may be
# a couple of lines long
print "Adding label...";
$text_back->Annotate(undercolor=>'white',
font=>'LCALLIG.TTF',
pointsize=>36,
fill=>'black',
gravity=>'Center',
text=>$names);