Open OTF fonts with php - greek characters included

magtak picture magtak · Jan 4, 2012 · Viewed 8.5k times · Source

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

Answer

Hossein picture Hossein · Jan 4, 2012

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.