简体   繁体   English

ImageMagick无法在我的机器上创建文本-Perl

[英]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. 本质上,Draw()方法可以正常工作,但Annotate()方法却无能为力。 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. 我相信我的机器或ImageMagick的安装都有问题,但我不知道出了什么问题。

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? 有谁知道为什么我不能让ImageMagick显示文本?

Some information about my setup: 有关我的设置的一些信息:

OS X Mavericks 10.9.3; OS X Mavericks 10.9.3; ImageMagick 6.8.9-1 / PerlMagick 6.88 (installed thru Homebrew) ImageMagick 6.8.9-1 / PerlMagick 6.88(通过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. 我在perlmonks帖子上找到了解决方案。 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! 希望这对遇到此问题的其他人有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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