Problems related to echo in image output of gd Library

Source: Internet
Author: User
Question about gd Library image output and echo & lt ;? Php & nbsp; header (& quot; Content-type: image/png & quot ;); // notify the browser to output images in PNG format $ im = imagecreatetruec gd Library image output and echo problems

Header ("Content-type: image/png"); // notify the browser to output an image in PNG format
$ Im = imagecreatetruecolor (400, 30); // Create a x Pixel canvas

$ White = imagecolorallocate ($ im, 255,255,255); // create a white image
$ Gray = imagecolorallocate ($ im, 128,128,128); // create a gray image
$ Black = imagecolorallocate ($ im, 0, 0, 0); // create a black
Imagefilledrectangle ($ im, 0, 0,399, 29, $ black); // outputs a rectangle filled with white as the background

// If there is a Chinese output, it needs to be transcoded, converted to a UTF-8 string can be passed directly
$ Text = iconv ("GB2312", "UTF-8", "LAMP brothers-no brother, no programming! ");
$ Font = 'simsun. ttc '; // specify the font to copy the font corresponding to simsum. ttc in the system to the current directory.
Imagettftext ($ im, 20, 0, 12, 21, $ gray, $ font, $ text); // output a gray string as the shadow.
Imagettftext ($ im, 20, 0, 10, 20, $ black, $ font, $ text); // output a black string on the shadow.


Imagepng ($ im); // outputs a PNG image to the browser
Imagedestroy ($ im); // destroys resources and releases the space occupied by memory.
Echo "aaaaaaaaaaaaa ";

?>

The echo statement in the last line of the above code cannot be output. why?


------ Solution --------------------
Output! Do not believe that you can use the binary editing software to open the generated image and ensure that there is aaaaaaaaaaaaa at the end of the file.

Since header ("Content-type: image/png"); // notify the browser to output an image in PNG format
Then the aaaaaaaaaaaaa will become part of the image.
------ Solution --------------------
Two different data streams cannot be output at the same time
------ Solution --------------------
There is a way. You want to output an image and display a text. Make the html page. Change the link of the image to the link for generating the image.
------ Solution --------------------
There should be no error

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.