I try to draw some text on the image. For that I use imagettftext()
:
$sign_str = "плюс";
$img = imagecreatetruecolor(360, 150);
$font = "StalinistOne-Regular.ttf";
$background_color_arr = array(rand(0, 255), rand(0, 255), rand(0, 255));
$background_color = imagecolorallocate($img, $background_color_arr[0], $background_color_arr[1], $background_color_arr[2]);
$font_color = imagecolorallocate($img, 255-$background_color_arr[0], 255-$background_color_arr[1], 255-$background_color_arr[2]);
imagefill($img, 0, 0, $background_color);
$x = rand(0, 135);
for($i = 0; $i < strlen($sign_str); $i++) {
$x+=25;
$letter=substr($sign_str, $i, 1);
imagettftext ($img, rand(20, 30), rand(2, 4), $x, rand(72, 80), $font_color, $font, $letter);
}
ImagePNG ($img);
ImageDestroy ($img);
But I get some strange symbols (not cyrillic, not empty rectangles like if the font doesn't support it).
And in "fonts" app in my system I can see that this font support cyrillic:
What do I do wrong? I tried to look some solutions on SO and not only, but they didn't work for me.
Working with GD ( imagettftext() ) and UTF-8 characters
PHP function imagettftext() and unicode
etc.