Return to Snippet

Revision: 495
at July 16, 2006 18:04 by jkochis


Initial Code
example: 
	$imgId = $_FILES['article_image']['name'];
	//make thumbnail
	$this->ImageManager->makeImage(WWW_ROOT.'/img/articleImages/'.$imgId, WWW_ROOT.'/img/articleThumbs/'.$imgId, 85, 110);


<?php
class ImageManagerComponent extends Object
{
	var $controller; 
	
	function makeImage($input, $output, $max_width, $max_height)
	{
		ob_start();
		$im = imagecreatefromjpeg($input);
		$orig_height = imagesy($im);
		$orig_width = imagesx($im);
		$ratio = ($orig_height>$orig_width) ? $max_width/$orig_width : $max_height/$orig_height;
		$new_width = $orig_width * $ratio;
		$new_height = $orig_height * $ratio;
		$new_im = imagecreatetruecolor($new_width,$new_height);
		imagecopyresampled($new_im,$im,0,0,0,0,$new_width,$new_height,$orig_width,$orig_height);
		imagejpeg($new_im);
		$image = ob_get_clean();
		$thumb_pointer = fopen($output,'w+');
		fputs($thumb_pointer,$image,strlen($image));
		fclose($thumb_pointer);
	}
	
	function delete($fileName)
	{
		if (unlink($fileName))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
?>

Initial URL

                                

Initial Description
makes a resized duplicate of an image

Initial Title
Image Manager Componet

Initial Tags
php, image, cakephp

Initial Language
PHP