简体   繁体   中英

ImageMagick not creating text on my machine - Perl

I recently took over someone else's position on a project. When the below code was run on their old machine, it worked fine. But when I run it, I get a blank white line with a yellow rectangle with a red outline. Essentially, the Draw() method works fine, but the Annotate() method isn't doing anything. No matter what values I pass it for text, font, fontsize, or color, no text will show up.

Here's the relevant code:

my ($length,$width,$boxRef,$text,$font,$fontSize,$fontColor,$outFile) = @_;

my $image = Image::Magick->new;
$image->Set(size=>$length."x".$width);
$image->ReadImage('xc:white');
$image->Draw(primitive=>'rectangle',stroke=>'red',fill=>'yellow',points=>"$$boxRef[0],$$boxRef[1],$$boxRef[2],$$boxRef[3]");
my $y = $image->Annotate(text=>$text,font=>$font,fill=>$fontColor,pointsize=>$fontSize,geometry=>'+0+20');
warn "$y" if "$y";
my $x = $image->Write($outFile);
warn "$x" if "$x";
undef $image;

I'm pretty sure nothing is wrong with the code, as other simpler scripts won't work either. I believe there is something wrong with my machine or installation of ImageMagick, but I have no idea what is wrong.

My boss said that he remembers the previous person struggling with some font issue, so maybe that has something to do with it? I've been doing some digging the past day or so, but I haven't found anything that seems to be quite like my problem that offers a good solution.

Does anyone know why I can't get ImageMagick to display text?

Some information about my setup:

OS X Mavericks 10.9.3; ImageMagick 6.8.9-1 / PerlMagick 6.88 (installed thru Homebrew)

I figured it out everyone! It turns out it was indeed an issue with the fonts. I found the solution on a perlmonks post. Even if the font used is on the machine, sometimes it will not find it (but on other machines it will for whatever reason). So the location has to be hard-coded in.

Changed the annotation line to the following:

# font has to be hard-coded in
my $y = $image->Annotate(text=>$text,font=>'/System/Library/Fonts/Courier.dfont',fill=>$fontColor,pointsize=>$fontSize,geometry=>'+0+20');

Hope this helps anyone else who comes across this problem!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM