问题
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