【问题标题】:Issues writing text to an image with PHP ImageMagick使用 PHP ImageMagick 将文本写入图像的问题
【发布时间】:2012-11-14 15:59:17
【问题描述】:

我尝试使用以下代码使用 imagemagick 创建一个 png。

<?php
/* Create some objects */
$image = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel( 'gray' );

/* New image */
$image->newImage(800, 75, $pixel);

/* Black text */
$draw->setFillColor('black');

/* Font properties */
$draw->setFont('Oxin_free_promo.ttf');
$draw->setFontSize( 30 );

/* Create text */
$image->annotateImage($draw, 10, 45, 0, 'The quick brown fox jumps over the lazy dog');

/* Give image a format */
$image->setImageFormat('png');

/* Output the image with headers */
header('Content-type: image/png');
echo $image;

但我不断收到以下错误。 /usr/local/zend/tmp/ 被修改为 777 并由 daemon:zend 拥有,而 magick-* 不存在。有什么想法吗?

httpd: FreeType library is not available `/Users/gareth.williams/Sites/_tests/texttoimg/Oxin_free_promo.ttf'.
httpd: Postscript delegate failed `/usr/local/zend/tmp/magick-tmfNBDIx': No such file or directory.
PHP Fatal error:  Uncaught exception 'ImagickException' with message 'Unable to annotate image'

【问题讨论】:

  • 您的网络服务器的用户 ID 是否对该 ../tmp 文件夹具有写入权限?
  • 试试这个:sudo chmod 777 /usr/local/zend/tmp/
  • 在更改服务器设置之前,您应该尝试找出为什么 Imagick 创建一个临时文件而不是只在内存中工作!
  • @aykut chmod 没用,权限已经差不多了
  • 取决于您运行脚本的方式。如果它在网络服务器下,那么运行网络服务器的用户 ID 需要具有访问权限。如果它是命令行,那么它将在运行该 shell 的任何人的 ID 下运行。

标签: php macos imagemagick zend-server


【解决方案1】:

查看给出的错误消息,它说明了问题所在。

“FreeType 库不可用” - ImageMagick 使用 FreeType 库来渲染字体,你给了它一个 TTF 来使用,它说 FreeType 没有安装,所以它不能使用字体。安装 FreeType,然后重新安装/重新编译 ImageMagick 以获得 FreeType 支持。

第二个错误可能是 ImageMagick 试图回退到使用其 postscript 光栅化支持来渲染字体,通常是通过ghostscript (gs),因此 “Postscript 委托失败”ghostscript 不可用,或者它要求 ghostscript 渲染的临时文件的路径也/来自不可写。正如人们在问题的 cmets 中提到的那样,可以通过安装 ghostscript 并确保临时目录具有完全写入权限来修复。

要确认这些原因,请使用转换的-list 选项。

  • convert -list format :这将显示支持的文件类型,查找 TTF,确保它至少具有 r-- 状态,如果 FreeType 安装正确,它应该显示类似 "TTF* TTF r-- TrueType font (Freetype 2.2.1)" 的内容。

  • convert -list delegate :这将显示委托类型的处理和使用的命令行。它将使用ps 转换器之一作为后备。

正如我所说,最简单的解决方法是安装 FreeType,然后重新编译/重新安装 ImageMagick。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-14
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-27
    • 2017-09-30
    相关资源
    最近更新 更多