6

So, as the title says, my task is to convert a given phrase to an image on server side (php GD) with a selected .otf font. The phrase can include not only latin characters but also greek and cyrillic.

PHP's imagettftext (http://php.net/manual/en/function.imagettftext.php) won't work with non-latin characters on .otf fonts (works ok with .ttf as it seems).

Any clues?

EDIT: Font needs to be .otf

magtak
  • 986
  • 1
  • 9
  • 20
  • 1
    Why not convert it to TTF then? – kapa Jan 04 '12 at 08:51
  • and do it for free at :http://www.freefontconverter.com/ –  Jan 04 '12 at 08:54
  • my bad for haven't added this to the question: I _need_ the features .otf offers that aren't present in .ttf – magtak Jan 04 '12 at 08:58
  • 2
    What features are those exactly? – Bojangles Jan 04 '12 at 09:00
  • It is a good question whether you need those features for this image-conversion, or for something else. You could store them in two different formats. – kapa Jan 04 '12 at 09:01
  • for image conversio. To give you the full picture: It's for a store that sells fonts and it needs an online presentation of it's fonts in the way that I described it before. Enter text + choose font + other features like underlines or whatever + produce image. – magtak Jan 04 '12 at 09:06
  • well in short nothing in native php will do this, you will have to look at other applications you can run on the server. –  Jan 04 '12 at 09:25

2 Answers2

11

Use imagefttext function instead. It has the same arguments and usage as imagettftext, but uses the FreeType 2 library which supports OpenType and plenty of other font formats.

It doesn't support OpenType's layout tables however. See FreeType 2's FAQ for more info.

Hossein
  • 4,097
  • 2
  • 24
  • 46
  • have you tried imagefttext with non-latin characters? Can't seem to get it to work either. Getting that annoying rectangle. – magtak Jan 05 '12 at 07:46
-4

Posting rough answer that seems to work for future people bumping on this post:

Solution seemed to be: 1) open OTF with LATEX server side 2) produce PDF 3) convert to image with ImageMagick library.

magtak
  • 986
  • 1
  • 9
  • 20