0

I have ImageMagick installed on my CentOS linux server.

I am trying to get ImageMagick to convert unicode (non-roman) fonts to an image. I am able to do this with roman/Latin based fonts but not non-latin such as chinese.

EDIT* When I try to convert non-latin fonts they show up as garbage such as %$??W*??

I have installed unicode fonts on my system and update the ImageMagick type.xml file to reflect this (i have update my locate db as well).

when I run (in my shell):# identify -list Type

I can see that my fonts are installed and that ImageMagick sees them but they (non-latin fonts) still do not work when I run my text-to-image conversion php script

I have checked out another article relating to this : Make ImageMagick recognize a font

But after doing everything there I still have the same problem. Please help.

Thanks.

EDIT: This is the some code related to imagemagick initialization:

            $font = 'UNICODE.TTF';  
    /* Create imagickdraw object */
    $draw = new ImagickDraw();
    $draw->setFont($font);
    $draw->setStrokeAntialias(true);
    $draw->setTextAntialias(true);
            $draw->setFontSize(100);
            $draw->setTextEncoding("UTF-8");

          //and than there is a bunch of code I use to manipulate the image shadow etc.

UPDATE Since receiving help via the comments to this post I have learned:

  1. That ImageMagick is capable of converting unicode non-latin characters This was tested by passing a hebrew word to ImageMagick via the linux command line.

  2. Therefore the problem is in the ImageMagick PHP module's ability to interpret unicode non-latin text.

  3. The php file itself has all the necessary elements to support UTF-8 and does in fact create a file with a filename derived from the same text varible I am passing to ImageMagick for image creation. The filename is successfully saved on my server by the php in non-latin unicode text.

I have looked around on the net and cannot find any information on this issue when it comes to using the ImageMagick PHP modules to create and image from text in unicode non-latin font.

Could this be a ImageMagick bug? Any help would be appreciated. thanks.

Community
  • 1
  • 1
Zigglzworth
  • 6,645
  • 9
  • 68
  • 107
  • You should elaborate how exactly the non-latin fonts do not work. Do they crash the server? Not show up at all? Show up garbled? – phihag Jan 31 '11 at 11:47
  • Yeah. sorry. I added an EDIT. Thanks. – Zigglzworth Jan 31 '11 at 11:51
  • 1
    You need to show more detail. How are you passing the data to ImageMagick? Can you make a concrete example of some garbled characters? What encoding is the data in that you feed to ImageMagick? If you have some code, please show it. – Pekka Jan 31 '11 at 11:54
  • Encodings are in UTF-8 . this is not a code problem it is an ImageMagick configuration problem. as I show in the edit that is the kind of garbage I am getting. – Zigglzworth Jan 31 '11 at 11:57
  • This is almost certainly not a font configuration or imagemagick problem, but rooted in the way you call imagemagick. Post a short code example that produces this error. Most likely, you did not call $draw->setTextEncoding('UTF-8'); – phihag Jan 31 '11 at 12:11
  • @user please show an *exact* example of the garbage – Pekka Jan 31 '11 at 12:40
  • Added an edit with some code. I am calling $draw->setTextEncoding('UTF-8'); by the way. – Zigglzworth Jan 31 '11 at 12:48
  • @Pekka: Exact garbage example - the Hebrew word המברגר becomes x?x?x?x"x?x" – Zigglzworth Jan 31 '11 at 13:20
  • @user hmm. Does it work when you pass Hebrew text to IM on the command line? – Pekka Jan 31 '11 at 14:17
  • @Pekka: Good suggestion. I tried and it works but the lettering is not ordered correctly meaning it is not right to left... but this brings me closer to a solution. – Zigglzworth Jan 31 '11 at 16:17
  • @user then it is an encoding issue, 99% sure (RTL is probably a separate thing). – Pekka Jan 31 '11 at 16:17
  • For RTL see http://studio.imagemagick.org/discourse-server/viewtopic.php?f=1&t=8139&start=0 for some discussion – Pekka Jan 31 '11 at 16:18
  • @Pekka. I see... but im not sure what more I can add to the code regarding encoding.. I have $draw->setTextEncoding('UTF-8'); and tried using utf8_encode()... – Zigglzworth Jan 31 '11 at 16:25
  • @user see my first comment. Where is the Hebrew text coming from using which encoding? – Pekka Jan 31 '11 at 17:02
  • @Pekka: it is encoded in UTF-8 and is coming from an html input field. I am also using that same variable (where the text is held) to create a file on my server (the filename) and it is working and saving files with unicode characters.. so only the imagemagick php functions seem to have a problem recognizing the text... – Zigglzworth Jan 31 '11 at 17:07

1 Answers1

0

The solution to this problem was found in a coding issue not seen here which occurs later in my PHP. Basically I split up the string into separate characters and needed to do so in a way that wont destroy 2-byte unicode characters.

I didn't think to show the rest of my code for people trying to help me solve this issue which was a big mistake on my part. lesson learned.

Zigglzworth
  • 6,645
  • 9
  • 68
  • 107