Marko Vasic
Marko Vasic

Reputation: 301

creating thumbnails without saving them

I need to create a page that will automatically create a thumbnail from all images if selected folder and show them on the same page. But the thing is, I don't want to save them. I want to display them on the same page without saving. And I need to do that in PHP. Is it possible? Please help! Note: If that is not possible,I can put them in some folder.

Upvotes: 1

Views: 1528

Answers (3)

abo400zar500
abo400zar500

Reputation: 1

replace this line

list($width, $height) = getimagesize($im);

with this

list($width, $height) = getimagesize("image.png");

Upvotes: 0

Brian
Brian

Reputation: 15706

You might also consider using data URIs. Use the code in DRP96's answer to create the thumbnail, but instead of doing it in a separate PHP and requiring many image requests, embed the images directly on the page.

Most modern browsers support data URIs now, but as usual, watch out for IE.

Upvotes: 0

Dion
Dion

Reputation: 3335

You have to make a second PHP-file then. You have to make an image tag in the first file <img src='image.php' /> and in this image.php you have to print out the image like:

header("Content-type: image/png");

$im     = imagecreatefrompng("image.png");
list($width, $height) = getimagesize($im);
$newimage = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($newimage, $im, 0, 0, 0, 0, "100", "100", $width, $height);

imagepng($newimage);
imagedestroy($newimage);
imagedestroy($im);

Upvotes: 2

Related Questions