As you never gave an example of WHAT you tried , I can assume that the subject is what you are attempting to do. Bestfit annotation. That is NOT posible!
Bestfit is for the label: image generation - it has nothing to to with 'annotate' which is a much lower level image drawing operator requiring an existing canvas! annotate does not have best fit capability.
The code to 'bestfit' is built into the coder for "label:" itself. As such it should be independent on the actual API used. The key is to ensure that the 'size' parameter is passed on to the call to readImage "label:" Specifically non-zero size and a zero (undefined) pointsize.
This worked for me!!!
Code: Select all
use Image::Magick;
$label=Image::Magick->new(size=>"600x600");
$label->Read("label:testing");
$label->Write("test.png");
What label does is attempts multiple pointsizes until it finds one that JUST fits inside the bounds specified. See "coders/label.c" and ReadLABELImage(). You should be able to follow the code as a programmer, even if you are not specifically a C programmer.
Actually this is the first time I even looked at that specific code myself.
It doubles the pointsize (starting at the default 12) until font is too big,
Then tried subtracting one until the text bound does fit.
After it has the right pointsize it carries on normal, creating the images canvas, handling gravity, and annotating the image onto the canvas. Oh and it reports the resulting point size it decided on in a Image Properity (setting) so you can look it up.
If you have an existing canvas and want to do 'bestfit' annotation (not image creation), then you will need to DIY it. However it is probably easier to create a bestfit label, and then compose that label onto the existing canvas. Slightly slower, but definitely easier.