Search code examples
phpunicodeimagettftext

Unicode-compatible alternative to imagettftext()


What other server-side tools are out there for creating textual images from TTF/OTF font files? I can't get imagettftext() to render Chinese/Japanese glyphs (even when defining the input string using HTML entities such as $#44032; as suggested here: PHP function imagettftext() and unicode).


Solution

  • I ended up invoking ImageMagick from within PHP:

    $command = 'printf "'.$text.'" | convert -size x'.(5*$size).' -gravity center -background "#00000000" -fill "#000000FF" -font '.$fontpath.' -pointsize '.$size.' label:@- -trim '.$imagepath;
    exec($command);