Analysis:
1, confirm the GB library is installed correctly? There is no report that this method does not exist.
2, Imagettftext () must be utf-8 coding, PHP's entire project is Utf-8 code, so don't think too much. If not, you can mb_convert_encoding () conversion;
3, check the font is loaded correctly, write dead font path, and changed a number of fonts (commonly used in Chinese font files are SIMSUN.TTC and Simhei.ttf), or not, to confirm that it should not be a font problem.
Then see the Internet, someone said: Please check whether you have added the –ENABLE-GD-JIS-CONV option when compiling the GD library, this option is to allow the GD library to support the Japanese-encoded font, please cancel this option and recompile.
Then I looked at my PHP compilation options, and I added this parameter, do I have to recompile?
Just as my eggs hurt, I saw an article:
$str =mb_convert_encoding (' kanji ', ' html-entities ', ' utf-8 '); Convert to HTML encoding
example , the specific code is as follows (file format is gb2312):
<?php
$im = Imagecreatefromjpeg ('./1.jpg ');
$w = Imagesx ($im);
$h = Imagesy ($im);
$green = Imagecolorallocate ($im, 50,100,200);
$str = Iconv (' gb2312 ', ' utf-8 ', ' happiness is on the side ');/solve garbled problem
Imagettftext ($im, 16,0,200,100, $green, './simhei.ttf ', $str);
Header ("Content-type:image/jpeg");
Imagejpeg ($im);
Imagedestroy ($im);
?>
Example 2
The transcoding method is not complicated, don't be nervous. The word "I love you" paste in Notepad, and then save as UTF8 format text, that is, the Unicode Utf-8 format, any word to save, it is called Test.txt Bar. Next: Open test.txt with a 16-in text editor, and you'll see text formatting like: Chr (0xe6), and so on, copy the code in these formats, and then look at the following function, I'm sure you've read it.
<?php
Output "I love You" in the graphics function of PHP
$cur _COUNT=CHR (0xe6). chr (0x88). chr (0x91). chr (0xe7). chr (0x88). chr (0XB1). chr (0xe4). chr (0xBD). chr (0xa0). chr (0xEF) . chr (0xBC). chr (0X81);
Header ("Content-type:image/gif");
$im = Imagecreate (156,116);
$black = Imagecolorallocate ($im, 0,0,0);
$blue = Imagecolorallocate ($im, 0,0,255);
$white = Imagecolorallocate ($im, 255,255,255);
$yellow = Imagecolorallocate ($im, 255,255,0);
Imagettftext ($im, 20,0,4,40, $yellow, "Simkai.ttf", $cur _count);//I choose the local font is in italics, you must select the fonts that exist in the system font.
Imagegif ($im);
Imagedestroy ($im);
?>