Create A Thumbnail Image in PHP Code (5g.html)

The following PHP code will create a thumbnail image:

$src = (isset($_GET['file']) ? $_GET['file'] : "");
$width = (isset($_GET['maxwidth']) ? $_GET['maxwidth'] : 73);
$thname = "xxx";

$file_extension = substr($src, strrpos($src, '.')+1);

switch(strtolower($file_extension)) {
   case "gif": $content_type="image/gif"; break;
   case "png": $content_type="image/png"; break;
   case "bmp": $content_type="image/bmp"; break;
   case "jpeg":
   case "jpg": $content_type="image/jpg"; break;

default: $content_type="image/png"; break;

}

if (list($width_orig, $height_orig, $type, $attr) = @getimagesize($src)) {
$height = ($width / $width_orig) * $height_orig;
}

$tn = imagecreatetruecolor($width, $height) ;
$image = imagecreatefromjpeg($src) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

imagejpeg($tn, './media/'.$thname.'.'.$file_extension, 90);

Click here to return to ePC Articles


Source:stackoverflow article
Webmaster:David@ColeCanada.com
/5g.html