Thumbnailer
$imageID = $_GET['id'];
$image_array = get_gallery_image($imageID);
$imagefile = "gallery/images/" . $image_array['Directory'] . "/" . $image_array['Filename'];
$thumb = "gallery/images/" . $image_array['Directory'] . "/thumbs/130x130_" . $image_array['Filename'];
if (!file_exists($thumb)) {
list($width, $height) = getimagesize($imagefile) ;
$modwidth = 130;
$modheight = 130;
if (($width / $modwidth) > ($height / $modheight)) {
$modheight = $height * ($modwidth / $width);
} else {
$modwidth = $width * ($modheight / $height);
}
$extension_loc = strrpos($imagefile, ".");
$extension = substr($imagefile, $extension_loc);
switch ($extension) {
case ".jpg":
case ".jpeg": $tn = imagecreatetruecolor($modwidth, $modheight);
$image = imagecreatefromjpeg($imagefile);
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);
// Here we are saving the .jpg, you can make this gif or png if you want
//the file name is set above, and the quality is set to 100%
imagejpeg($tn, $thumb, 100);
break;
case ".gif": $tn = imagecreatetruecolor($modwidth, $modheight);
imagegif($tn, $thumb);
break;
case ".png": $tn = imagecreatefrompng($modwidth, $modheight);
imagepng($tn, $thumb);
break;
}
}
header("Location: $thumb");