A simple php drawing problem. I wrote the following code on the php page: & lt ;? Phpheader (Content-Type: textjpeg); this field can be correctly executed if it is commented out. $ Imimagecreatetruecolor (200,200); imagepng ($ im );? & Gt; you cannot draw an image if it is not commented out. The browser also prompts you to download (Download 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