Strange imagepng problems

Source: Internet
Author: User
Images & quot;) can be obtained, but the code cannot be displayed in the browser. it is always a red cross. this code can run normally on another machine. Is it my php configuration problem? & Lt ;? Strange question about header (& quot; Content-type imagepng
The code is as follows. it is strange that you can change imagepng ($ im) to imagepng ($ im, "kk.png") to get an image, but the image cannot be displayed in the browser, this code can run normally on another machine. Is it my php configuration problem?
Header ("Content-type: image/png ");
Srand (double) microtime () * 1000000 );
$ Login_check_number = strval (rand ("11111", "99999 "));
// $ Session-> setMember ("loginCheckNumber", $ login_check_number );

$ Im = imagecreate (50, 20) or die ("Cannot Initialize new GD image stream ");
$ Black = ImageColorAllocate ($ im, 9,142,204 );
$ ForeColor = ImageColorAllocate ($ im, 0, 0 );
$ White = ImageColorAllocate ($ im, 255,255,255 );
Imageline ($ instant, 1, 1,350, 25, $ black );
Imagearc ($ im, 200, 15, 20, 20, 35,190, $ white );
Imagestring ($ im, 5, 7, 3, $ login_check_number, $ white );
For ($ I = 0; $ I <100; $ I ++) // add interference pixels
{
Imagesetpixel ($ im, rand () % 50, rand () % 50, $ foreColor );
}

Imagepng ($ im );
Imagedestroy ($ im );
?>


------ Solution --------------------
Discussion
Reference:
Reference:
If the GD library is not open, can imagepng ($ im, "kk.png" examples generate kk.png files?

It should be related to the browser.
Replace the first sentence with the header ("Content-type: image/x-png ");


I can't change it either.

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.