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.