PHP ImageMagic unicode 字符
perl -e 'binmode(STDOUT, ":utf8"); \
print "\x{201C}Unicode \x{2018}\x{263A}\x{2019} Please\x{201D}";' |\
convert -background lightblue -fill blue -pointsize 36 \
label:@- label_unifun.gif
我正在尝试按照 ImageMagick 文档在 PHP 中实现相同的结果。然而,至今还没有结果。这就是我所拥有的:
$draw = new ImagickDraw();
$draw->setTextEncoding('UTF-8');
$draw->setFontSize(52);
$draw->setFont("font.otf");
$draw->setStrokeAntialias(TRUE);
$draw->setTextAntialias(TRUE);
$draw->annotation(20, 50, "\x{201C}Unicode \x{2018}\x{263A}\x{2019} Please\x{201D}");
$canvas = new Imagick();
$canvas->newImage(1000, 500, "red");
$canvas->drawImage($draw);
$canvas->setImageFormat('png');
header("Content-Type: image/png");
echo $canvas;
但它只打印 \x{201C}Unicode \x{2018}\x{263A}\x{2019} Please\x{201D}
。
perl -e 'binmode(STDOUT, ":utf8"); \
print "\x{201C}Unicode \x{2018}\x{263A}\x{2019} Please\x{201D}";' |\
convert -background lightblue -fill blue -pointsize 36 \
label:@- label_unifun.gif
I am trying to follow ImageMagick documentation to achieve the same result in PHP. However, so far with no result. This is what I have:
$draw = new ImagickDraw();
$draw->setTextEncoding('UTF-8');
$draw->setFontSize(52);
$draw->setFont("font.otf");
$draw->setStrokeAntialias(TRUE);
$draw->setTextAntialias(TRUE);
$draw->annotation(20, 50, "\x{201C}Unicode \x{2018}\x{263A}\x{2019} Please\x{201D}");
$canvas = new Imagick();
$canvas->newImage(1000, 500, "red");
$canvas->drawImage($draw);
$canvas->setImageFormat('png');
header("Content-Type: image/png");
echo $canvas;
But it just prints \x{201C}Unicode \x{2018}\x{263A}\x{2019} Please\x{201D}
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PHP 会在将其传递给 ImageMagick 时为您进行转义,只需将未转义的 Unicode 字符插入到字符串中即可:
PHP will do the escaping for you when passing it to ImageMagick, just insert your Unicode characters un-escaped into your string:
我使用命令行工具并接受使用 file_put_contents() 创建的中间文件中的标题/标签以支持 UNICODE 字符。
I use the command line tool and accept the caption / label from an intermediate file which is created using file_put_contents() to support UNICODE characters.