2

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.

Onur Kucukkece
  • 1,708
  • 1
  • 20
  • 46
  • If you solve the problem yourself, it's probably best to post the fix as an answer instead of as an update to the question. That way you can accept it, others can upvote it, and your question gets removed from the Unanswered Questions list. – Jeffrey Blake May 10 '12 at 13:51
  • @JeffreyBlake I couldn't solve the problem yet. It occurs because the encoding of the document is not defined. – Onur Kucukkece May 10 '12 at 14:11
  • My mistake. When I saw your update, I thought you were stating that you had solved it. – Jeffrey Blake May 10 '12 at 14:12
  • Is your actual PHP script (the code itself) encoded in UTF-8? – John Flatness May 10 '12 at 14:32
  • @JohnFlatness I opened the document in notepad and saved it in UTF-8 but then imagick cannot output the image, only some many characters – Onur Kucukkece May 10 '12 at 15:07
  • You do not say if you are saving the image or just displaying it. What happens if you have a page with the Imagick code and the headers set to image/png and you then use that on your main page with – Bonzo May 10 '12 at 16:09
  • @Bonzo Problem occurred in both way, and in both way characters seemed broken in the image, but I found the solution, utf8_decode() function fixes it – Onur Kucukkece May 11 '12 at 06:43

1 Answers1

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

........
Onur Kucukkece
  • 1,708
  • 1
  • 20
  • 46
  • Hi I tried your solution to my problem. But it still does not work. Maybe I did not set the utf-8 format correctly. How do I ensure that? My problem is stated here: http://stackoverflow.com/questions/11101544/how-to-use-imagick-annotateimage-for-chinese-text – Kim Stacks Jun 20 '12 at 15:08