The image output of GD library and Echo related problems

Source: Internet
Author: User
GD library image output and echo problem

Header ("Content-type:image/png"); Notifies the browser that an image formatted as PNG will be output
$im = Imagecreatetruecolor (400, 30); Create a 400x300 pixel-sized canvas

$white = Imagecolorallocate ($im, 255, 255, 255); Create White
$grey = Imagecolorallocate ($im, 128, 128, 128); Create Gray
$black = imagecolorallocate ($im, 0, 0, 0); Create Black
Imagefilledrectangle ($im, 0, 0, 399, $black); Output a rectangle with white fill as the background

If there is a Chinese output, it needs to be transcoded and converted to a UTF-8 string to be passed directly
$text =iconv ("GB2312", "UTF-8", "lamp brother Lian--no brother, no programming!") ");
$font = ' SIMSUN.TTC '; Specifies the font to copy the font corresponding to the SIMSUM.TTC in the system to the current directory
Imagettftext ($im, 0, $grey, $font, $text); Output a gray string as a shadow
Imagettftext ($im, 0, $black, $font, $text); Output a black string on top of the shadow


Imagepng ($im); Export images in PNG format to the browser
Imagedestroy ($im); Destroying resources, freeing up memory footprint
echo "AAAAAAAAAAAAAAA";

?>

The Echo statement from the last line of the above code is out of the print, why?


------Solution--------------------
The output! I don't believe you. Using binary editing software to open the resulting picture, ensure that there is aaaaaaaaaaaaaaa at the end of the file

Since the header ("Content-type:image/png"); Notifies the browser that an image formatted as PNG will be output
Then that AAAAAAAAAAAAAAA is part of the picture.
------Solution--------------------
Two different data streams cannot be output at the same time
------Solution--------------------
Wood has a way. You want to output a picture, and you want to display a paragraph of text. The HTML page is not the only line. The link to the image is changed to create a link to the image
------Solution--------------------
There should be no mistake
  • 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.