note 95007 deleted from function.imagejpeg by thiago
| From: | thiago@php.net | Date: | Tue, 08 Dec 2009 15:17:31 +0000 |
| Subject: | note 95007 deleted from function.imagejpeg by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-163713@lists.php.net to get a copy of this message | ||
Note Submitter: John McLean
----
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.