PHP generates images. Chinese display garbled
PHP generates the Chinese part of the picture. Become garbled. How to solve ...?
The following I am my Code
The fonts have 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
Drawing
Imagefill ($im, 0,0, $background _color);//Fill background
5 Horizontal lines
Imageline ($im, 0, 0, $width, 0, $lin _color);
Imageline ($im, 0, 199, 199, 199, $lin _color);
Imageline ($im, 0, $width, $lin _color);
Imageline ($im, 0, $width, $lin _color);
Imageline ($im, 0, $width, $lin _color);
5 vertical lines
Imageline ($im, 0, 0, 0, $height, $lin _color);
Imageline ($im, 199, 0, 199, 199, $lin _color);
Imageline ($im, 0, $height, $lin _color);
Imageline ($im, N, 0, $height, $lin _color);
Imageline ($im, 0, $height, $lin _color);
Enter text
$str =iconv ("Gb2312", "UTF-8", "Chinese");
$font = ' Arial.ttf ';
Imagettftext ($im, 0, 10,10, $text _color, $font, $STR);
Output image
Imagepng ($im);
Clean
Imagedestroy ($im);
?>
------Solution--------------------
PHP Code
!--? php
//Set the Content-type
header ("content-type:image/p Ng ");
//Create the image
$im = Imagecreatetruecolor (400, 30);
//Create some colors
$white = imagecolorallocate ($im, 255, 255, 255);
$grey = imagecolorallocate ($im, 128, 128, 128);
$black = imagecolorallocate ($im, 0, 0, 0);
Imagefilledrectangle ($im, 0, 0, 399, $white);
//The text to draw
$text = ' founder cartoon simplified ... ';
//Replace path by your own font path
$font = ' founder cartoon simplified. TTF ';
$text = iconv (' gb2312 ', ' utf-8 ', $text) #[color= #FF0000]attention[/color]
//Add Some shadow to the text
Imag Ettftext ($im, 0, one, one, $grey, $font, $text);
//Add The text
Imagettftext ($im, 0, ten, $black, $font, $text);
//Using imagepng () results in clearer text compared with imagejpeg ()
Imagepng ($im);
Imagedestroy ($im);
?>