filectime($cacheFile))) { //if ($imgInfo[0]<$outWidth){$outWidth=$imgInfo[0];} //if ($imgInfo[1]<$outHeight){$outHeight=$imgInfo[1];} // Create output image $outImg = imagecreatetruecolor ($outWidth, $outHeight); // Load src image switch($srcType) { case "png": $srcImg = imagecreatefrompng($uri); $blending = false; break; case "gif": $srcImg = imagecreatefromgif($uri); $blending = true; break; case "jpeg": $srcImg = imagecreatefromjpeg($uri); break; default: diewith("unsupported file type '$uri'"); }; // preserve transparency for PNG and GIF images if ($srcType == 'png' || $srcType == 'gif'){ // allocate a color for thumbnail $background = imagecolorallocate($outImg, 0, 0, 0); // define a color as transparent imagecolortransparent($outImg, $background); // set the blending mode for thumbnail imagealphablending($outImg, $blending); // set the flag to save alpha channel imagesavealpha($outImg, true); } // Resize image imagecopyresampled($outImg, $srcImg, 0, 0, 0, 0, $outWidth, $outHeight, $srcWidth, $srcHeight); // Save to cached thumb switch($srcType) { case "png": $res = imagepng($outImg, $cacheFile); break; case "gif": $res = imagegif($outImg, $cacheFile); break; case "jpeg": $res = imagejpeg($outImg, $cacheFile, 85); break; default: diewith("unsupported file type '$uri'"); } // Check result if (!$res) diewith("Unable to save thumb to '$cacheFile'. Check the access right of the HTTP server."); } // HTTP Header header("Content-Type:image/$srcType"); // Dump cache file readfile($cacheFile) or diewith("Unable to open cached thumb '$cacheFile'"); ?>