note 94079 added to function.imagejpeg
| From: | vesselin dot stoykov at promobile dot bg | Date: | Thu, 15 Oct 2009 12:18:08 +0000 |
| Subject: | note 94079 added to function.imagejpeg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161762@lists.php.net to get a copy of this message | ||
Re: function resizeImage by someone at anydomain dot com
To display more than a single image in the browser, please, call that function from html for every
single image you want to see. However, in the function you need to add header() before you call
imagejpeg() and exit() instead of "return". Code of "test.php" may look like
this:
<?php
if(isset($_GET['img']))
resizeImage($_GET['img'],123);
function resizeImage($originalImage,$new_height){
// Get the original geometry and calculate scales
list($width, $height) = getimagesize($originalImage);
$new_width = round(($width * $new_height) / $height);
// Resize the original image
$imageResized = imagecreatetruecolor($new_width, $new_height);
$imageTmp = imagecreatefromjpeg ($originalImage);
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width,
$height);
/* CHANGE HERE: */
header('Content-type: image/jpeg');
imagejpeg($imageResized, null, 100);
imageDestroy($imageResized);
exit();
}
echo <<<END
<html><body>
<img src="test.php?img=DSC00680.JPG">
<img src="test.php?img=DSC00679.JPG">
</body></html>
END;
?>
The above works. Slowly. Mind that imagecreatefromjpeg() works slowly for large jpg's (>1MB)
and resizing of 10 images may take a long time or even server timeout may occur before the script
has terminated.
Certainly you'd better use php to scan your "images" directory and make an array of
valid file names and then echo them into the html. Even better, in the img url you may use only the
serial number of the jpg file from the array instead of its qualified name, e.g.: <img
src="test.php?img=1">. Change also the call to resizeImage() accordingly.
----
Server IP: 217.75.128.29
Probable Submitter: 89.190.194.50
----
Manual Page -- http://www.php.net/manual/en/function.imagejpeg.php
Edit -- https://master.php.net/note/edit/94079
Del: integrated -- https://master.php.net/note/delete/94079/integrated
Del: useless -- https://master.php.net/note/delete/94079/useless
Del: bad code -- https://master.php.net/note/delete/94079/bad+code
Del: spam -- https://master.php.net/note/delete/94079/spam
Del: non-english -- https://master.php.net/note/delete/94079/non-english
Del: in docs -- https://master.php.net/note/delete/94079/in+docs
Del: other reasons-- https://master.php.net/note/delete/94079
Reject -- https://master.php.net/note/reject/94079
Search -- https://master.php.net/manage/user-notes.php