Looking to render complex fonts (with diacritics, joined glyphs, right to left text) in various languages/scripts, output is an image (not web page), ideally need to use PHP. The commonly built in graphics libraries for PHP, Imagick and GD, don't support complex fonts, I believe because the version of Freetype they come with doesn't support it.
I've looked into custom building PHP with the possible support but it looks horribly complex and messy.
Any thoughts on an easier solution for this?
Thanks
This a problem I faced a lot too, imagettftext
is the most use GD function to write text on a image but the problem with this is that it can't render complex unicode characters, so as long as your language does not have complex characters we are good.
To render complex unicode characters you may need imagick
installation plus pango
installed on your server. Most of the hosting providers do not have pango installed so that means you need to have a dedicated server ready for your application.
most of the linux distributions comes with pango
pre installed so if you managed to install imagick
on your local linux matchine
following code should work without any problem
/* complex unicode string */
$text = "වෙබ් මත ඕනෑම තැනක";
$im = new \Imagick();
$background = new \ImagickPixel('none');
$im->setBackgroundColor($background);
$im->setPointSize(30);
$im->setGravity(\Imagick::GRAVITY_EAST);
$im->newPseudoImage(300, 200, "pango:" . $text );
$im->setImageFormat("png");
$image = imagecreatefromstring($im->getImageBlob());
//just for print out to the browser
ob_start();
imagepng($image);
$base64 = base64_encode(ob_get_clean());
$url = "data:image/png;base64,$base64";
echo "<img src='$url' />";
Let me know if you find any difficulties with the code