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}
。
答案 0 :(得分:0)
PHP会在将其传递给ImageMagick时为您进行转义,只需将未转义的Unicode字符插入到字符串中:
$draw->annotation(20, 50, "ééèeèeèaèèèààaàaàaààêêêçcçcçc");
答案 1 :(得分:0)
我使用命令行工具并接受来自使用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;