diff options
Diffstat (limited to 'utils/imagecache.php')
| -rw-r--r-- | utils/imagecache.php | 56 | 
1 files changed, 35 insertions, 21 deletions
| diff --git a/utils/imagecache.php b/utils/imagecache.php index 3f91d79..5adf54c 100644 --- a/utils/imagecache.php +++ b/utils/imagecache.php @@ -7,16 +7,38 @@ include_once($UTIL_DIR . "/modules.php");  class ImageSize {  	public $width;  	public $height; +  public $cut; -	public function ImageSize($w, $h) +	public function ImageSize($w, $h, $c)  	{  		$this->width = $w;  		$this->height = $h; +    $this->cut = $c;  	}  }; -function rescale($image, $width, $height) +function rescale_nocut($image, $maxwidth, $maxheight)  { +	$width = imagesx($image); +	$height = imagesy($image); + +	if($width <= $maxwidth && $height <= $maxheight) return $image; + +	$scale = 1; +	if($width > $maxwidth) $scale = $width / $maxwidth; +	if($height / $scale > $maxheight) $scale = $height / $maxheight; + +	$image_p = imagecreatetruecolor($width / $scale, $height / $scale); +	imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width / $scale, +                     $height / $scale, $width, $height); + +	return $image_p; +} + +function rescale($image, $width, $height, $cut) +{ +  if($cut == false) return rescale_nocut($image, $width, $height); +    $aspect = $width / $height;  	$w = imagesx($image); @@ -60,27 +82,19 @@ function errorImage($message)  function getCachedImage($filename, $mod, $cat)  { -	global $modules; -	loadModule($mod); -	if(!$modules[$mod]) die(404); -	if(!method_exists($modules[$mod], "getImageSize")) die(404); +	$module = loadModule($mod); +	if(!$module) die(404); +	if(!method_exists($module, "getImageSize")) die(404); -	$size = $modules[$mod]->getImageSize($cat); +	$size = $module->getImageSize($cat);  	$maxwidth = $size->width;  	$maxheight = $size->height; +  $cut = $size->cut; -	/* -	if($mod == "discography") { -		if($cat == "cover") { $maxwidth = 100; $maxheight = 100; } -	} -	if($mod == "gallery") { -		if($cat == "randomimage") { $maxwidth = 100; $maxheight = 100; } -		if($cat == "photo") { $maxwidth = 100; $maxheight = 100; } -		if($cat == "albumicon") { $maxwidth = 100; $maxheight = 100; } -	} -	*/  	global $IMAGECACHE, $JPEG_CACHE_QUALITY; -	$fullfilename = $IMAGECACHE . "/" . $maxwidth . ":" . $maxheight . ":". urlencode($filename); +  $cutstr = "uncut"; +  if($cut) $cutstr = "cut"; +	$fullfilename = $IMAGECACHE . "/" . $maxwidth . ":" . $maxheight . ":" . $cutstr . ":" . urlencode($filename);  	// Test the storage dir  	if(!file_exists($IMAGECACHE)) { @@ -106,21 +120,21 @@ function getCachedImage($filename, $mod, $cat)  			case ".jpg":  				$image = imagecreatefromjpeg(urldecode($filename));  				if(!$image) errorImage("Could not read: ". $filename); -				$image = rescale($image, $maxwidth, $maxheight); +				$image = rescale($image, $maxwidth, $maxheight, $cut);  				imagejpeg($image, $fullfilename, $JPEG_CACHE_QUALITY);  				break;  			case ".gif":  				$image = imagecreatefromgif(urldecode($filename));  				if(!$image) errorImage("Could not read: ". $filename); -				$image = rescale($image, $maxwidth, $maxheight); +				$image = rescale($image, $maxwidth, $maxheight, $cut);  				imagegif($image, $fullfilename);  				break;  			case ".png":  				$image = imagecreatefrompng(urldecode($filename));  				if(!$image) errorImage("Could not read: ". $filename); -				$image = rescale($image, $maxwidth, $maxheight); +				$image = rescale($image, $maxwidth, $maxheight, $cut);  				imagepng($image, $fullfilename);  				break; | 
