PHP Imagick - setTextEncoding() function doesn't work

痞子三分冷 提交于 2019-12-08 01:52:36

问题


I'm trying to add some text on a Imagick object.

However I use setTextEncoding() function, it still doesn't work.

.......

$draw = new ImagickDraw();
$draw->setTextEncoding('utf-8');
$draw->setFont($fpath.'/process/ARIAL.TTF'); 
$draw->setFontSize(80);
$draw->setFillColor("#ffffff");

/*** annotate the text on the image ***/
$imageOrg->annotateImage($draw, 60, 100, 0, "onur küçükkeçe");

........

and as a result I get,

onur küçükkeçe

Any idea why it's not working?

Thanks in advance.

UPDATE

if I set a $text variable to something like chr(252) then I get a proper result

$text=chr(252);
$imageOrg->annotateImage($draw, 60, 100, 0, $text);

as a result I get

ü

UPDATE II

Finally I found what causing this.

The problem occurs because the charset of the document is not defined but if set a charset for the script then imagick doesn't work because the type of the document needs to be set to image/png.

But I don't know how can I fix it.


回答1:


Ok. I found the solution.

php utf8_decode() function solves the problem

.......

$draw = new ImagickDraw();
$draw->setTextEncoding('utf-8');
$draw->setFont($fpath.'/process/ARIAL.TTF'); 
$draw->setFontSize(80);
$draw->setFillColor("#ffffff");

/*** annotate the text on the image ***/
$imageOrg->annotateImage($draw, 60, 100, 0, utf8_decode("onur küçükkeçe"));

........


来源:https://stackoverflow.com/questions/10533210/php-imagick-settextencoding-function-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!