A simple php drawing problem,

Source: Internet
Author: User
A simple php drawing problem. I wrote the following code on the php page: & lt ;? Php // header ('content-Type: text/jpeg '); // If commented, the execution is correct. $ Im = imagecreatetruecolor (200,200); imagep a simple php drawing problem ,,,
I wrote the following code on the php page:
// Header ('content-Type: text/jpeg '); // If commented, the execution is correct.
$ Im = imagecreatetruecolor (200,200 );
Imagepng ($ im );
?>

If the above part is not annotated, the image cannot be drawn. The browser also prompts you to download the image (it is not an image after it is downloaded), or open it (it is garbled after it is opened ).
Question: Do I not need to have this header () to specify the type for drawing? Is it related to the configuration file of php. ini? Or other reasons.

------ Solution --------------------
You output the browser, you have to tell it, what type of things do you want to output to others ??
For example, html is text/html ....
------ Solution --------------------
I don't understand. if I comment it out, the MIME type should be text/html. how can I still display the image?
In addition, you output the png format, while the header sends the jpeg format. Change consistency
------ Solution --------------------
Header ('content-Type: image/png '); // Note: it is image rather than text
$ Im = imagecreatetruecolor (200,200 );
Imagepng ($ im );

Red must be matched

Whether the type declaration header is required depends on the browser type
------ Solution --------------------
Header ('content-Type: image/jpeg '); image is the specified image Type.
------ Solution --------------------
Example 1. create a new GD image stream and output the image

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.