Php generates images. The Chinese text is garbled .. It turns into garbled characters .. How can this problem be solved ..? Below I copied the font of my code to my Directory: & lt ;? Phpheader (& quot; Content-type: imagepng & quot;); $ height200; $ width200; $ im @ imagecreate ($ width, $ height) ord php generates an image. Garbled characters in Chinese
Php generates the Chinese part of the image .. It turns into garbled characters .. How can this problem be solved ..?
Below is my code
The font has been copied to my Directory:
Header ("Content-type: image/png ");
$ Height = 200;
$ Width = 200;
$ Im = @ imagecreate ($ width, $ height) or die ("Cannot Initialize new GD image stream ");
// Color settings
$ Background_color = imagecolorallocate ($ im, 255,255,255); // background color
$ Lin_color = imagecolorallocate ($ im, 209,124, 2); // Line color
$ Text_color = imagecolorallocate ($ im, 209,124, 2); // text color
// Draw
Imagefill ($ im, $ background_color); // fill the background
// 5 CrossLines
Imageline ($ im, 0, 0, $ width, 0, $ lin_color );
Imageline ($ im, 0,199,199,199, $ lin_color );
Imageline ($ im, 0, 50, $ width, 50, $ lin_color );
Imageline ($ im, 0,100, $ width, 100, $ lin_color );
Imageline ($ im, 0,150, $ width, 150, $ lin_color );
// Five vertical bars
Imageline ($ im, 0, 0, 0, $ height, $ lin_color );
Imageline ($ im, 199, 0,199,199, $ lin_color );
Imageline ($ im, 50, 0, 50, $ height, $ lin_color );
Imageline ($ im, 100, 0,100, $ height, $ lin_color );
Imageline ($ im, 150, 0,150, $ height, $ lin_color );
// Input text
$ Str = iconv ("Gb2312", "UTF-8", "Chinese ");
$ Font = 'Arial. ttf ';
ImageTTFText ($ im, 13, 0, 10, $ text_color, $ font, $ str );
// Output image
Imagepng ($ im );
// Clear
Imagedestroy ($ im );
?>
------ Solution --------------------
PHP code
// Set the content-type
Header ("Content-type: image/png ");
// Create the image
$ Im = imagecreatetruecolor (400, 30 );
// Create some colors
$ White = imagecolorallocate ($ im, 255,255,255 );
$ Gray = imagecolorallocate ($ im, 128,128,128 );
$ Black = imagecolorallocate ($ im, 0, 0, 0 );
Imagefilledrectangle ($ im, 0, 0,399, 29, $ white );
// The text to draw
$ Text = 'simplified founder cartoon ...';
// Replace path by your own font path
$ Font = 'Simplified Chinese simplified. ttf ';
$ Text = iconv ('gb2312', 'utf-8', $ text); # [color = # FF0000] Attention [/color]
// Add some shadow to the text
Imagettftext ($ im, 20, 0, 11, 21, $ gray, $ font, $ text );
// Add the text
Imagettftext ($ im, 20, 0, 10, 20, $ black, $ font, $ text );
// Using imagepng () results in clearer text compared with imagejpeg ()
Imagepng ($ im );
Imagedestroy ($ im );
?>