PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
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.
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);
My general technique for this is to annotate to an area larger than required, and see if that larger area was needed. (In most cases, this means trimming it, and ensuring this is smaller in both dimensions than the required area.)