duanqiao1926 2011-08-16 12:34
浏览 100
已采纳

Imagemagick不会显示文本,但也不会抛出任何错误

I'm using ImageMagick to generate some product badges for products in our system. Product badges are like SO flair, just a few composite images and some text. There is nothing wrong with the script as it runs fine on my development machine which runs Windows. However, on my production system (CentOS 5.1), it renders everything except the text.

I thought this was a font issue, but it doesn't work even if I copy the font file to the PHP file location nor did it work when I gave it a full path.

And it didn't work when I installed the Windows fonts for Linux as described here.

I've typed convert -list font and it shows a list of fonts that Imagick knows about (parital list shown below)

  Font: Times-BoldItalic
    family: Times
    style: Italic
    stretch: Normal
    weight: 700
    glyphs: /usr/share/fonts/default/Type1/n021024l.pfb
  Font: Times-Italic
    family: Times
    style: Italic
    stretch: Normal
    weight: 400
    glyphs: /usr/share/fonts/default/Type1/n021023l.pfb
  Font: Times-Roman
    family: Times
    style: Normal
    stretch: Normal
    weight: 400
    glyphs: /usr/share/fonts/default/Type1/n021003l.pfb

I tried giving the absolute path listed here and it didn't work. I also tried just using the name and still nothing.

Basically the image shows up, but the text parts of it don't show up at all and no errors are thrown (see images below).

There's nothing wrong with the code and both Windows and CentOS are running close versions of Imagick (6.7.1-4 and 6.7.1-3). The only issue could be the font, I'm just putting normal TTF fonts up and testing, do I need some kind of special font to get it to work?

Working

Working Image

Broke

Broken Image

EDIT - Ignore the differences in the QR code and the ratings. This is due to the working badge and the non working badge being on two different servers.

UPDATE 1 - I've run a simple test script and even that doesn't work. This is what I ran as a test : http://us2.php.net/manual/en/function.imagick-annotateimage.php The font just doesn't show up and no errors are thrown.

I've also copied a font from the CentOS system and tried it on the Windows box and it works fine. Fonts simply don't seem to work on CentOS.

I've also tried it without setting a font, I assume Imagick picks up a default font or something, and again works on Windows, but not on CentOS. I'm going to try this on a different *nix version to see what happens. Will update with findings.

Update 3 : I've narrowed the issue down to a problem with the FreeType library I think. The forums say that FreeType needs to be installed for text to be displayed properly. And when I look at the config.log it tells me that there is an issue installing FreeType. Any heads up on this would be appreciated, meanwhile I'm going to re-install Freetype and run the installation again.

  • 写回答

1条回答 默认 最新

  • doupinyan0186 2011-08-18 18:24
    关注

    You can't just install Freetype. You actually have to install Freetype on your server, then recompile ImageMagick using the --with-freetype-dir=/usr/local option. Where /usr/local is the path to your Freetype install.

    I believe it's normally /usr/local/bin

    Give that a whirl and let us know what happens ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄