PHP generates images. Garbled Chinese display

Source: Internet
Author: User
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);
?>


  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.