The following php code produces correct results on Windows, but not on Linux.
I have no idea how to solve the problem, does anyone can give me a hint? The font is the standard Roboto font from google, which contains all required characters, as I can see under Windows.
<?php
header('Content-Type: image/jpeg');
$total_width = 500; // Breite Gesamtbild
$total_height = 120; // Höhe Gesamtbild
$dst_img = imagecreatetruecolor($total_width, $total_height); // leeres Bild anlegen
$bg_color = imagecolorallocate($dst_img, 255, 255, 240); // Hintergrundfarbe festlegen
$rand_color = imagecolorallocate($dst_img, 224, 123, 21); // Randfarbe festlegen
$text_color = imagecolorallocate($dst_img, 1, 1, 1); // Textfarbe festlegen
imagefill($dst_img, 0, 0, $bg_color); // Hintergrundfarbe malen
imagerectangle ($dst_img, 0, 0, $total_width-1, $total_height-1, $rand_color); // Rand malen
imagerectangle ($dst_img, 1, 1, $total_width-2, $total_height-2, $rand_color); // Rand malen (zweites Pixel)
$rp = realpath('');
$txtfont = "$rp/Roboto/Roboto-Regular.ttf";
$txt1 = "Viele Grüße";
$txt2 = html_entity_decode($txt1, ENT_QUOTES, 'UTF-8');
$txt3 = "Viele Grüße";
imagettftext($dst_img, 12, 0, 15, 28, $text_color, $txtfont, $txt1);
imagettftext($dst_img, 12, 0, 15, 58, $text_color, $txtfont, $txt2);
imagettftext($dst_img, 12, 0, 15, 88, $text_color, $txtfont, $txt3);
imagejpeg($dst_img); // Bild liefern
imagedestroy($dst_img); // Speicher freigeben
?>
Expexted was to see the same result on Linux as on Windows
2
Answers
After some more experiments, I know the problem is not the font. On Windows all works as expected. On the Linux of my provider, the problem is that imagettftext does not work with umlauts created by html_entity_decode. But it works with numeric character references.
So I wrote the following helper function for use as a replacement of html_entity_decode:
Just to see whether the problem is with the font or with the function imagettftext, I wrote a small test. It should produce the same table twice. On Windows, it works as expected, on Linux it does not.
This is the output on Windows:
This is the output on Linux:
And this is the test code: