rendered paste bodydefine("IMAGE_FULL", 0);define("IMAGE_THUMB", 1);define("IMAGE_TINY", 2);$IMAGE_PATHS = array( IMAGE_FULL => "images/", IMAGE_THUMB => "images/thumb/", IMAGE_TINY => "images/tiny/");function imagePath($filename, $pathtype = IMAGE_FULL){ global $IMAGE_PATHS; if($pathtype < IMAGE_FULL || $pathtype > IMAGE_TINY) $pathtype = IMAGE_FULL; $fullPath = $IMAGE_PATHS[IMAGE_FULL].$filename; if(!file_exists($fullPath)){ return $fullPath; // whelp, you're getting a broken image. } if($pathtype == IMAGE_THUMB){ // 133x100 $destPath = $IMAGE_PATHS[IMAGE_THUMB].$filename; if(!file_exists($destPath)){ makeThumb($fullPath, $destPath, 133, 100); } return $destPath; } elseif($pathtype == IMAGE_TINY) { // 50x50 $destPath = $IMAGE_PATHS[IMAGE_TINY].$filename; if(!file_exists($destPath)){ makeThumb($fullPath, $destPath, 50, 50); } return $destPath; } else { //IMAGE_FULL return $IMAGE_PATHS[IMAGE_FULL].$filename; }}function makeThumb($source, $dest, $width, $height){ list($srcWidth, $srcHeight, $typeConst) = getimagesize($source); $srcAspect = $srcWidth/$srcHeight; $destAspect = $width/$height; $scale = 1.0; $gdSrc; $gdDest = imagecreatetruecolor($width, $height); if($srcAspect > $destAspect){ // fit to height $scale = $height / $srcHeight; } else { // fit to width $scale = $width / $srcWidth; } $finalWidth = $scale * $srcWidth; $finalHeight = $scale * $srcHeight; $finalX = ($width - $finalWidth)/2; $finalY = ($height - $finalHeight)/2; switch($typeConst){ case IMAGETYPE_GIF: $gdSrc = imagecreatefromgif($source); break; case IMAGETYPE_JPEG: $gdSrc = imagecreatefromjpeg($source); break; case IMAGETYPE_PNG: $gdSrc = imagecreatefrompng($source); break; default: return; // what the hell did you upload? a bitmap? you don't deserve a thumbnail. break; } // Do the resize and resample imagecopyresampled($gdDest, $gdSrc, $finalX, $finalY, 0, 0, $finalWidth, $finalHeight, $srcWidth, $srcHeight); switch($typeConst){ case IMAGETYPE_GIF: imagegif($gdDest, $dest); break; case IMAGETYPE_JPEG: imagejpeg($gdDest, $dest); break; case IMAGETYPE_PNG: imagepng($gdDest, $dest); break; }}