开发者

PHP ImageMagic unicode characters

  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}.


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");


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜