【发布时间】:2012-09-23 18:39:16
【问题描述】:
我正在使用 MySQL 数据库来保存一些字体。我需要使用自定义字体系列文本创建图像。我正在使用 SplTempFileObject 来处理 setFont 方法,但这是 imagick 所说的:
Fatal error: Uncaught exception 'ImagickDrawException' with message 'The given font is not found in the ImageMagick configuration and the file ($_SERVER['DOCUMENT_ROOT]php:/temp) is not accessible'
(当然 $_SERVER['DOCUMENT_ROOT'] 是真正的价值,我只是替换它):)
任何解决方案或者我必须将字体保存在文件系统中?
代码如下:
$image = new \Imagick();
$draw = new \ImagickDraw();
$temp = new \SplTempFileObject();
$temp->fwrite($font->getFile()->getContent());
$image->newImage(550, 50, "black");
$draw->setFont($temp);
$font 是来自数据库的数据。我认为问题是因为 ImagickDraw::setFont() 相对于 DOC ROOT 搜索字体。
【问题讨论】:
-
var_dump(is_dir($_SERVER['DOCUMENT_ROOT'].'php:/temp')) 输出什么?
-
您能否添加显示您正在使用的代码
SplTempFileObject -
@artragis 不,这不是目录。它不应该是。我想说的是,imagick 搜索相对于文档根目录的字体。
-
所以你想通过绝对地址访问文件?
-
@artragis 我不知道这是否是问题所在。与
$draw->setFont('/'.$temp->getFileName());相同的问题。我想将 SplTempFileObject 与 setFont 一起使用,而不是将文件写入文件系统。