popoffka
Новичок
Проблема с кодировкой при создании картинки
Вот код программы на РНР:
Её задача - брать текст из $text и наносить его на картинку.
Но есть проблема - русские символы почему-то отображаются крякозябрами( можете запустить и проверить).
Шрифт Andale Mono, который должен лежать в папке с программой, можно скачать отсюда.
Объясните пожалуйста, почему у меня возникает такая проблема, и как её устранить?
Вот код программы на РНР:
PHP:
<?
// 82 символа на 1 строку
// 8 строчек * 82 символа в строке = не более 656 символов в посте
//CONFIG
$width = 500;
$height = 125;
$im = imagecreate($width, $height);
$font_text = './andalemo.ttf';
$font_mono = './andalemo.ttf';
$text_size = 8;
$info_size = 7;
$bgcolor = ImageColorAllocate($im, 247, 247, 247);
$text_color = ImageColorAllocate($im, 0, 0, 0);
$colorLetraFondo = ImageColorAllocate($im, 247, 247, 247);
$blog_name = 'Blog of the genius developer';
$author = 'popoffka';
$text = "Тест русского текста. This is just a test pic of my post in mine pStatus microblog. Now it's in a very early stage of a developement. It now don't have any interfaces or databases, it works in debug mode. And it dont't supports Russian symbols :( But i believe, that after some time of working at this project, we'll have a fully working microblog system ;)";
$textlen = strlen($text);
$num_of_lines = $textlen / 82;
$drob = $num_of_lines - substr($num_of_lines, 0, 1);
$to_add = 1 - $drob;
$real_nol = $num_of_lines + $to_add;
$author_text = "Author: ".$author.$count;
header("Content-type: image/png");
imagettftext($im, $info_size, 0, 0, 10, $text_color, $font_mono, $author_text);
imagettftext($im, $info_size, 0, 250, 10, $text_color, $font_mono, $blog_name);
imagettftext($im, 7, 0, 0, 120, $text_color, $font_mono, '(c) pstatus.hyperphp.com');
$difference = $text_size + 4;
$i = 1;
$j = 0;
while ($i <= $real_nol) {
$top = 18 + $difference * $i;
$line[$i] = substr($text, $j, 82);
imagettftext($im, $text_size, 0, 0, $top, $text_color, $font_text, $line[$i]);
$i++;
$j = $j + 82;
}
imagepng($im);
imagedestroy($im);
imagedestroy($im2);
?>
Но есть проблема - русские символы почему-то отображаются крякозябрами( можете запустить и проверить).
Шрифт Andale Mono, который должен лежать в папке с программой, можно скачать отсюда.
Объясните пожалуйста, почему у меня возникает такая проблема, и как её устранить?