note 95007 added to function.imagejpeg
| From: | JohnMcLean at osu1 dot php dot net | Date: | Tue, 08 Dec 2009 14:05:11 +0000 |
| Subject: | note 95007 added to function.imagejpeg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-163712@lists.php.net to get a copy of this message | ||
Response to someone at anydomain dot com:
You are only seeing one image because your script outputs a single jpeg. Subsequent jpeg images are
disregarded. What you need to do is construct a normal html page with <img> tags with a src
attribute pointing to your script, passing the filename as a parameter. As a matter of good
practice, you should also output filetype:jpeg headers.
For example, use this script as "image.php":
<?php
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);
// Output
imagejpeg($imageResized, null, 100);
imageDestroy($imageResized);
return;
}
header("Content-Type: image/jpeg")
$filename = $_GET['f'];
resizeImage($filename,100);
exit;
?>
Then show your images using the following html page (head etc. omitted for clarity)
...
<body>
<img src="image.php?f=IMG_0158.JPG" />
<img src="image.php?f=IMG_0159.JPG" />
</body>
...
Note that if you are doing this on a high traffic page with lots of thumbnails, the server workload
will be appreciably higher than if you cache the thumbnails as jpgs and serve them as static images.
----
Server IP: 69.147.83.197
Probable Submitter: 80.169.193.85
----
Manual Page -- http://www.php.net/manual/en/function.imagejpeg.php
Edit -- https://master.php.net/note/edit/95007
Del: integrated -- https://master.php.net/note/delete/95007/integrated
Del: useless -- https://master.php.net/note/delete/95007/useless
Del: bad code -- https://master.php.net/note/delete/95007/bad+code
Del: spam -- https://master.php.net/note/delete/95007/spam
Del: non-english -- https://master.php.net/note/delete/95007/non-english
Del: in docs -- https://master.php.net/note/delete/95007/in+docs
Del: other reasons-- https://master.php.net/note/delete/95007
Reject -- https://master.php.net/note/reject/95007
Search -- https://master.php.net/manage/user-notes.php