Location: PHPKode > scripts > JPEG Slicer > jpeg-slicer/JPEGSlicer.php
<?php
/*<------------------------------------
	
	FILE 	= JPEGSlicer.php
	TYPE	= PHP CLASS
	AUTHOR	= ANISH KARIM C, <hide@address.com>
	DATE	= 20 Jan 2008
	
	DESCRIPTION : JPEGSlicer is a JPEG image resizer-Slicer class written in pure php.
	Whcich is used to resize and slice the entire image into 4 sub parts and this will be help to load the imge faster in the post upload section.
-------------------------------------->*/


class JPEGSlicer
{
	function JPEGSlicer($directory, $temp_image,$selection,$resize) 
	{
		
		
		$this->image_info		=	getimagesize($temp_image);
		if(strtolower($selection) == 'nill') //NO RESIZE NEEDED
		{
			$height	=	$this->image_info[1];
	 		$width	=	$this->image_info[0];
		}
		else if(strtolower($selection) == 'height') // IF THE FIXED SIZE IS HEIGHT
		{
			$height 	= 	$resize;
			$ratio		=	$height/$this->image_info[1];
			$width		=	ceil($this->image_info[0] * $ratio);
			
		}
		else if(strtolower($selection) == 'width')
		{
			$width	=	$resize;
			$ratio	=	$width/$this->image_info[0];
			$height	=	ceil($this->image_info[1] * $ratio);
		}
		@mkdir($directory,0777);
		@mkdir($directory.'/top_left',0777);
		@mkdir($directory.'/top_right',0777);
		@mkdir($directory.'/bottom_left',0777);
		@mkdir($directory.'/bottom_right',0777);
		
		$path[0]	=	$directory.'/top_left/';
		$path[1]	=	$directory.'/top_right/';
		$path[2]	=	$directory.'/bottom_left/';
		$path[3]	=	$directory.'/bottom_right/';
		
		$this->Slicer($path,$height,$width,$temp_image);
	}

	function Slicer($path,$height,$width,$tmp_img)
	{
		$this->filename		=	array();
		$full_width			=	$this->image_info[0];
		$full_height		=	$this->image_info[1];
		echo"<br>".$width." ".$height;
		$split_width		=	round($width/2);
		$split_height		=	round($height/2);
		
		for($i=0;$i<4;$i++)
		{
			
			$new_img		=	imagecreatetruecolor($width,$height);
			$original		=	imagecreatefromjpeg($tmp_img);
			imagecopyresized($new_img,$original,0,0,0,0,$width,$height,$full_width,$full_height)or die('Cannot Resize Image');
			
			if(($i+1)%3	== 0)
				{
					$init_x	=	0;
					$init_y	=	$split_height;
				}
		$this->filename[$i]	=	$path[$i].time().'.jpg';
		$cut_image	=	imagecreatetruecolor($split_width,$split_height);
					
		imagecopyresampled($cut_image,$new_img,0,0,$init_x,$init_y,$split_width,$split_height,$split_width,$split_height)or die('Cannot Resample');
			
				imagejpeg($cut_image,$this->filename[$i])or die('Cannot Write Image');
				imagedestroy($new_img);
				imagedestroy($cut_image);
				$init_x	=	$init_x+ $split_width;
				
			
		
		}

	}
}
?>
Return current item: JPEG Slicer