GenerateThumbnail.php

Generates thumbnail of an image and saving it in certain folder.
Edit php to set 1- Absolute folder path. 2- Thumbnail width (currently set to 220)
It will only needs the full http location of the image by passing src variable (as in example).
Can pass (in src variable) any image on the internet if you can open it in your browser.
Used in one of my websites.


Public

Tested

My Own Work
< ? php   
/*
Generate thumbnail image of an image passed as argument
To use ...
    GenerateThumbnail.php?src=/folder/image_large.jpg
Will return full image path and name along with the image itself ...
Needs ...
    Define the path to save thumbnail into inside the document
*/

// Needs a physical folder to save thumbnails to ..
$tofolder                    = '/C18-SPC/Thumbs/' ;
$folde                        = $_SERVER['DOCUMENT_ROOT'] . $tofolder;


$from_name                    = urldecode($_REQUEST['src']);
$from_base                    = basename($from_name);
$img                            = file_get_contents($_REQUEST['src']);
$im                            = imagecreatefromstring($img);
$width                            = imagesx($im);
$height                        = imagesy($im);
$newheight                    = '220';
// $newwidth                    = 220*$width/$height ;
$newwidth                    = $newheight * $width / $height ;
$thumb                        = imagecreatetruecolor($newwidth, $newheight);
imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, $folde . $from_base); //save image as jpg
imagedestroy($thumb);
imagedestroy($im);

echo $tofolder . $from_base . '
';
echo '<' . 'img src="' . $tofolder . $from_base . '" />';

?>

src

GenerateThumbnail.php?src=/folder/image_large.jpg

Views 328 Downloads 98

PHP Multimedia
ANmarAmdeen
793
Attachments
Revisions

v2.0