Php generates images. Garbled characters in Chinese

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


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.