Use Imagettftext to enter characters under a picture, you can't create a picture in a browser

Source: Internet
Author: User
Use Imagettftext to enter characters on a picture and not create a picture in the browser
I imagettftext the function to write the character string in the picture, but cannot output the picture in the browser, uses the Imagepng ($im, ' x.png '), can the picture output, but if the direct output to the browser but does not have, asks the master to be trained. The following my Code

Header (' content-type:image/png ');
Putenv (' gdfontpath=c:\windows\fonts ');
$button _text= ' button buttons ';
$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, 30,30, 0,150, $white, ' Msyh. TTF ', $button _text);
Imagepng ($im);//Use Imagepng ($im, ' x.png '); You can generate x.png, and pictures have text.
Imagedestroy ($im);
?>

------Solution--------------------
References:
References:

Reference:

Without any error, the browser is blank, but if you use IE browser, there will be some garbled. I try to use imagestring instead of imagettftext to output normally, if I want to remove Chinese characters ...


Imagestring does not support Chinese characters. can only Yong Imagettftext. If it is garbled, it is proved that the picture can be lost before it is generated
...
Utf-8 has two formats, one is utf-8 no BOM format, one is from the BOM header, instead of BOM header
------Solution--------------------
Reference:
I imagettftext the function to write the character string on the picture, but can not output the picture in the browser, use Imagepng ($im, ' x.png ');

This is just your program file with a BOM header. Just get rid of 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.