Can you help with an 'Unable to annotate image' error?
Posted: 2019-05-23T08:44:02-07:00
I am using php 7.0.19 and ImageMagick 6.9.6-4 on a FreeBSD 11.0 server. I use imagemagick for quite a few things, but I am just getting started with using it to overlay text on top of my images. The problem I'm having is that any time I try to use the annotateImage functionality an error is thrown that simply says 'Unable to annotate image.'
I have looked through quite a few questions related to annotateImage and I have checked the docs to see if I could resolve the issue on my own, but I'm stuck. On other annotateImage questions I have seen that some people have trouble due to not having a specific font installed, and that may be my problem as well, but I have tried placing a font file (the ttf file) in the same directory as my script and I am still having the same issue.
Running convert -list font returns an empty result, indicating that there are no fonts that imagemagick has direct/default access to; however, I was thinking that by including the font file in the same directory as my script I could make it work anyway. Perhaps this is a mistaken assumption?
Here is the code I am using for my test:
I have also tried other example scripts that don't require an original image, and received the same error. For example, this script produces the same error:
With these simple tests I was expecting to add 'The quick fox jumps over the lazy dog' to an image, but instead an exception is thrown and the error message simply says: Unable to annotate image.
Any ideas or suggestions on how I can resolve the error?
Thank you!
I have looked through quite a few questions related to annotateImage and I have checked the docs to see if I could resolve the issue on my own, but I'm stuck. On other annotateImage questions I have seen that some people have trouble due to not having a specific font installed, and that may be my problem as well, but I have tried placing a font file (the ttf file) in the same directory as my script and I am still having the same issue.
Running convert -list font returns an empty result, indicating that there are no fonts that imagemagick has direct/default access to; however, I was thinking that by including the font file in the same directory as my script I could make it work anyway. Perhaps this is a mistaken assumption?
Here is the code I am using for my test:
Code: Select all
$imagick = new Imagick('originalImage.jpg');
$draw = new ImagickDraw();
$draw->setFillColor('#ffffff');
$draw->setFont('/file/location/myfont.ttf');
$draw->setFontSize(20);
$imagick->annotateImage($draw, 20, 100, 0, 'The quick fox jumps over the lazy dog');
$imagick->drawImage($draw);
$imagick->writeImage('finalImage.jpg');
Code: Select all
$image = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel( 'gray' );
$image->newImage(800, 75, $pixel);
$draw->setFillColor('black');
$draw->setFont('/file/location/myfont.ttf');
$draw->setFontSize( 30 );
$image->annotateImage($draw, 10, 45, 0, 'The quick brown fox jumps over the lazy dog');
$image->setImageFormat('png');
header('Content-type: image/png');
echo $image;
Any ideas or suggestions on how I can resolve the error?
Thank you!