The image cannot be generated in the browser because imagettftext is used to input characters under the image.

Source: Internet
Author: User
Images); you can output images, but if you can directly output images to a browser, you cannot. The following is my code & lt ;? PhpHeader (Content-type: & nbsp; imag uses imagettftext to input characters on the image, and the image cannot be generated in the browser.
I wrote a Chinese character string in imagettftext.pdf on the image, which can be used to output the image in a browser and use imagepng(imim,'x.png '). I can output the image but cannot output it to a browser. My code below

Header ('content-type: image/png ');
Putenv ('gdfontpath = C: \ WINDOWS \ fonts ');
$ Button_text = 'Button ';
$ Button_text = $ button_text.rand (30, 50 );
$ Im = imagecreatetruecolor (400,200 );
$ Black = imagecolorallocate ($ im, 0, 0, 0 );
$ White = imagecolorallocate ($ im, 255,255,255 );
Imagefill ($ im, 0, 0, $ black );
Imagettftext ($ im, 0,150, $ white, 'msyh. ttf', $ button_text );
Imagepng ($ im); // use imagepng(immediate im,'x.png' to generate X.png. The image also contains text.
Imagedestroy ($ im );
?>

------ Solution --------------------
Reference:
Reference:

Reference:

There is no error message. the browser is blank, but some garbled characters will appear in IE browser. I try to replace imagettftext with imagestring to make the output work normally, provided that I want to remove Chinese characters ......


Imagestring does not support Chinese characters. Only yong imagettftext is supported. if it is garbled, it indicates that the image may be lost before it is generated ......

There are two UTF-8 formats: one is UTF-8 without bom, and the other is changed from bom header to bom header without bom header.
------ Solution --------------------
Reference:
Text.

This is only because your program file has a BOM header. Just remove it.

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.