All pastes #762806 Raw Edit

Mine

public php v1 · immutable
·published 2007-11-05 22:35 UTC
rendered paste body
<?php/*	@File:			thumbnail.class.php	@Author:		Dan Jeffers	@Date:			11.05.2007	@Note:			A thumbnail creation class created for Beat the Experts	@Dependancies:	GD2 Library		*/class ImageResize {		function __construct() {		}	public function loadImage($file, $newFile, $width, $height) {		$originalWidth	= '';		$originalHeight	= '';		$originalRatio	= '';		$newWidth		= '';		$newHeight		= '';		$fileExtension	= '';		$tempImage		= '';		$newImage		= '';		$newFileName	= '';		$size			= '';				$size = getimagesize($file);				if($size[0] < $width || $size[1] < $height)		{						return false;				} 								list($originalWidth, $originalHeight) = $size;				$originalRatio = $originalWidth / $originalHeight;				if($width / $height > $originalRatio)		{						$newWidth = $height * $originalRatio;				} else {					$newHeight = $width / $originalRatio;				}				$fileExtension = pathinfo($file);				$newImage = imagecreatetruecolor($width, $height);				$newFileName = basename($newFile, $fileExtension['extension'])  . strtolower($fileExtension['extension']);				switch($fileExtension['extension']) {					case 'jpg': case 'jpeg':				return $this->resizeJpeg($file, $newFileName, $newImage, $tempImage, $width, $height, $originalWidth, $originalHeight);				break;						case 'gif':				return $this->resizeGif($file, $newFileName, $newImage, $tempImage, $width, $height, $originalWidth, $originalHeight);			break;						case 'png':				return $this->resizePng($file, $newFileName, 9, $newImage, $width, $height, $originalWidth, $originalHeight);			break;						default:								return false;			break;						}	}		protected function resizeJpeg($file, $newFileName, $newImage, $width, $height, $originalWidth, $originalHeight) {			$tempImage = imagecreatefromjpeg($file);		imagecopyresampled($newImage, $tempImage, 0, 0, 0, 0, $width, $height, $originalWidth, $originalHeight);		if(!imagejpeg($newImage, $newFileName, 100))		{			return false;					} else { 			return true;					}			}		protected function resizeGif($file, $newFileName, $newImage, $width, $height, $originalWidth, $originalHeight) {			$tempImage = imagecreatefromgif($file);				imagecopyresampled($newImage, $tempImage, 0, 0, 0, 0, $width, $height, $originalWidth, $originalHeight);				if(!imagegif($newImage, $newFileName))		{					return false;				} else { 					return true;					}				}		protected function resizePng($file, $newFileName, $quality, $newImage, $width, $height, $originalWidth, $originalHeight) {			$tempImage = imagecreatefrompng($file);		imagecopyresampled($newImage, $tempImage, 0, 0, 0, 0, $width, $height, $originalWidth, $originalHeight);							if(!imagepng($newImage, $newFileName, $quality))		{						return false;					} else { 					return true;					}			}	}?>