<?php
	function mbResizeImage($table,$id,$field,$uploadUrl1,$newwidth1,$newheight1,$uploadUrl2,$newwidth2,$newheight2) {
		error_reporting(0);
		$change="";
		$abc="";
		define ("MAX_SIZE","1024");
			 function getExtension($str) {
					 $i = strrpos($str,".");
					 if (!$i) { return ""; }
					 $l = strlen($str) - $i;
					 $ext = substr($str,$i+1,$l);
					 return $ext;
			 }
			 $errors=0;
			 
	if($_SERVER["REQUEST_METHOD"] == "POST") {
		 
				$imagefiel =$_FILES["".$field.""]["name"];
				$uploadedfile = $_FILES["".$field.""]['tmp_name'];
				 ///Rename Image
		if(!empty($imagefiel)){
		
				$image = $id.'_'.$imagefiel;  //image new name
				
				if ($image) {
					$filename = stripslashes($image);
					$extension = getExtension($filename);
					$extension = strtolower($extension);
		
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) {
					$change='<div class="msgdiv">Unknown Image extension </div> ';
					$errer = 1 ;
					return $errer;
			}else{

			 $size=filesize($_FILES["".$field.""]['tmp_name']);
			if ($size > MAX_SIZE*1440)
			{
				$change='<div class="msgdiv">You have exceeded the size limit!</div> ';
				$errer = 1 ;
				return $errer;
			}
			if($extension=="jpg" || $extension=="jpeg" )
			{
			$uploadedfile = $_FILES["".$field.""]['tmp_name'];
			$src = imagecreatefromjpeg($uploadedfile);}
				else if($extension=="png")
				{
				$uploadedfile = $_FILES["".$field.""]['tmp_name'];
				$src = imagecreatefrompng($uploadedfile);
				}
				else 
				{
				$src = imagecreatefromgif($uploadedfile);
				}
				echo $scr;
				list($width,$height)=getimagesize($uploadedfile);
				
				
				
						if(empty($newwidth1)){
							if($height > $newheight1){
								$newwidth1=($width/$height)*$newheight1;
							}else{
								$newwidth1=$width;
								$newheight1=$height;
							}
						}
						if(empty($newheight1)){
							if($width > $newwidth1){
								$newheight1=($height/$width)*$newwidth1;
							}else{
								$newheight1=$height;
								$newwidth1=$width;
							}
						}
						$tmp1=imagecreatetruecolor($newwidth1,$newheight1);
						imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);
						$filename1 = $uploadUrl1.$image;
						imagejpeg($tmp1,$filename1,100);
						
						if(!empty($uploadUrl2)){
							if(empty($newwidth2)){
								if($height > $newheight2){
									$newwidth2=($width/$height)*$newheight2;
								}else{
									$newwidth2=$width;
									$newheight2=$height;
								}
							}
							if(empty($newheight2)){
								if($width > $newwidth2){
									$newheight2=($height/$width)*$newwidth2;
								}else{
									$newheight2=$height;
									$newwidth2=$width;
								}
							}
							$tmp2=imagecreatetruecolor($newwidth2,$newheight2);
							imagecopyresampled($tmp2,$src,0,0,0,0,$newwidth2,$newheight2,$width,$height);
							$filename2 = $uploadUrl2.$image;
							imagejpeg($tmp2,$filename2,100);
							imagedestroy($tmp2);
						}

				imagedestroy($src);
				imagedestroy($tmp1);
				}}

				return $image;
		}else{
			$errer = 2 ;
			return $errer;
		}
	}
}

?>