PHP ImageMagic unicode 字符

发布于 2024-10-22 04:30:14 字数 878 浏览 1 评论 0原文

  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

段念尘 2024-10-29 04:30:14

PHP 会在将其传递给 ImageMagick 时为您进行转义,只需将未转义的 Unicode 字符插入到字符串中即可:

$draw->annotation(20, 50, "ééèeèeèaèèèààaàaàaààêêêçcçcçc");

PHP will do the escaping for you when passing it to ImageMagick, just insert your Unicode characters un-escaped into your string:

$draw->annotation(20, 50, "ééèeèeèaèèèààaàaàaààêêêçcçcçc");
柳絮泡泡 2024-10-29 04:30:14

我使用命令行工具并接受使用 file_put_contents() 创建的中间文件中的标题/标签以支持 UNICODE 字符。

file_put_contents($textFilename, $text);

$cmd = "convert -size ".WIDTH."x".HEIGHT."  -background ".BACKGROUND_COLOR_TTI." -fill ".TEXT_COLOR_TTI." -pointsize ".FONT_SIZE_TTI." -gravity     center    caption:@".$textFilename." ".$newFileName;

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.

file_put_contents($textFilename, $text);

$cmd = "convert -size ".WIDTH."x".HEIGHT."  -background ".BACKGROUND_COLOR_TTI." -fill ".TEXT_COLOR_TTI." -pointsize ".FONT_SIZE_TTI." -gravity     center    caption:@".$textFilename." ".$newFileName;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文