dongren1353 2012-08-31 12:11
浏览 49
已采纳

Imagemagick - Same命令在PHP或控制台中提供不同的输出

I'm trying to use ImageMagick on an Ubuntu 12.04 server to create simple business cards dynamically. This is done via a php page. I tried to install MagickWand, but it didn't really work so I'm now using ImageMagick syntax and executing it via PHP function exec().

I'm making good progress, and had the basics more or less done, the output image looked okay and am now finetuning, setting the positions right, changing fonts and sizes, etc.

Our graphic person wants the text to be in Arial with bold titles, so I installed msttcorefonts on the server. Since then, the text in the output image is italic, and it ignores whatever font I use.

The curious thing is: if I echo the command to the page, copy and paste it into the ubuntu console, the image that's created there uses the right fonts and is exactly what I want.

So, it seems that when I execute the command via console, everything is fine, but when I execute it in PHP via exec(), ImageMagick doesn't seem to recognize the fonts. Does anyone know why? Also, if it doesn't recognize the font, why does it default to italic, or, for that matter, why did the default change at all after installing the fonts?

This is the command I'm currently testing (with changed names and contact info):

 convert                                                     \
    -size 1051x697                                           \
     xc:none                                                 \
    -density 300                                             \
    -fill white                                              \
     draw "rectangle 0,0 1051,697"                           \
    -fill black                                              \
    -font Arial-Negreta                                      \
    -pointsize 9                                             \
    -draw "text 140,175 'Hotel Example'"                     \
    -font Arial-Normal                                       \
    -pointsize 6                                             \
    -draw "text 140,220 'Example Street 8'"                  \
    -draw "text 140,240 '12345 Exampletown'"                 \
    -draw "text 140,280 'Telefon: 123 45 67 89 0'"           \
    -draw "text 140,300 'Fax: 234 56 78 90'"                 \
    -draw "text 140,340 'http://www.example.de'"             \
    -draw "text 140,360 'hotel-example@example.de'"          \
    -stroke none -fill orange -draw "rectangle 1,32 1050,75" \
    -fill grey                                               \
    -draw "rectangle 1,75 1050,100"                          \
    -fill orange                                             \
    -draw "rectangle 1,626 1050,665"                         \
     test_front.png

Edit:

I just noticed that running the command from the Ubunut console also only works in my home directory, and not in my /var/www directory. As APiK pointed out, it's probably a user thing.

  • 写回答

2条回答 默认 最新

  • dongyan2267 2012-08-31 12:52
    关注

    It looks like you installed the fonts only for a specific user. Try to run this command in console and PHP script:

    # This will show you all the available fonts for ImageMagick
    $ convert -list type
    

    Or you can also specify TTF fonts directly:

    $ convert -font /path/to/your/fonts.ttf
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM