Page 1 of 1

Thumbnail file creation - a better way?

Posted: Wed May 09, 2007 8:19 am
by Jenk
I've currently got a simple system of:

Code: Select all

<?php

$original = '/path/to/original.jpg';
$thumb = imagecreatetruecolor(100,100);
$size = getimagesize($original);
imagecopyresampled($thumb, $original, 0, 0, 0, 0, 100, 100, $size[0], $size[1]);

ob_start();
imagejpeg($thumb);
$content = ob_get_contents();
ob_end_clean();

file_put_contents('/path/to/thumbnail.jpg', $content);

?>
Is there a way to create a thumbnail like the above without the use of the output buffer?

Is there also a way to create a thumbnail before the original image is on disk? I.e. I have the file via $_FILES, but not on disk yet.

Posted: Wed May 09, 2007 8:59 am
by onion2k
imagejpeg() optionally takes a second argument of a filename that you can use to save the image.

imagecreatefromjpeg($_FILES['myUpload']['tmp_file']) works fine.

Pimp-my-website: http://www.phpgd.com/scripts.php?section=2 .. several ways to make thumbnails.

Posted: Wed May 09, 2007 11:44 am
by Jenk
Cheers. :)