note 105479 added to function.imagejpeg
| From: | dodgeit2 at yahoo dot com | Date: | Sun, 21 Aug 2011 18:33:56 +0000 |
| Subject: | note 105479 added to function.imagejpeg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-182626@lists.php.net to get a copy of this message | ||
Problem: The URL of the current page is displaying in the browser window as an image file. At the
same time your manipulated image saves to a file.
Solution: Start with removal of the header() function if you plan to output to a file. The browser
is expecting image information; therefore, if you are outputting to a file, you don't need a
header() function at all.
If you are outputting to the browser check your imagejpeg() for parameter 2. Set it to
'null' if it has a file name.
Many of the examples programmers illustrate on the web output to the browser and do not save
anything to the file system, therefore, the header() function seems essential to image manipulation
for the first-time user of the GD library.
This page actually clearly shows the difference between "outputting" to a browser and
"saving" to a file, but the code comments don't clearly state what the difference is.
Search for the page on the "header()" function on this website for more details.
Example: Let's say that you are outputting to a jpeg using imagejpeg(). Note the use of the
header() function when outputting to the browser.
<?php
/*
more
code
to
make
it
work
*/
// These just illustrate the different outputs.
// outputting to the browser
// header() needed for browser
header('Content-Type: image/jpeg')
imagejpeg($im);
// saving to a file
// you do not need a header() function to save to a file
imagejpeg($im, "../images/image001.jpg");
// outputting to the browser including quality parameter.
// skipping parameter2 to output to browser
header('Content-Type: image/jpeg');
imagejpeg($im, null, 90);
// saving to a file including quality parameter.
// all parameters used for saving to a file with quality adjustment
imagejpeg($im, "../images/image001.jpg, 90);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 76.20.11.210
----
Manual Page -- http://www.php.net/manual/en/function.imagejpeg.php
Edit -- https://master.php.net/note/edit/105479
Del: integrated -- https://master.php.net/note/delete/105479/integrated
Del: useless -- https://master.php.net/note/delete/105479/useless
Del: bad code -- https://master.php.net/note/delete/105479/bad+code
Del: spam -- https://master.php.net/note/delete/105479/spam
Del: non-english -- https://master.php.net/note/delete/105479/non-english
Del: in docs -- https://master.php.net/note/delete/105479/in+docs
Del: other reasons-- https://master.php.net/note/delete/105479
Reject -- https://master.php.net/note/reject/105479
Search -- https://master.php.net/manage/user-notes.php