<?php  

include_once('../header.php');
if(isset($_FILES['image']["type"])){		
        $iWidth = $iHeight = 200;
		/* $iWidth = $_POST['w']; */ 
		/* $iHeight = $_POST['h']; */
		/* 100; */ /* desired image result dimensions */
		$iJpgQuality = 90;	
		 $hh=$_POST['h'];
		 $ww=$_POST['w'];
		 $xx1=$_POST['x1'];
		 $yy1=$_POST['y1'];	
		 $xx2=$_POST['x2'];
		$yy2=$_POST['y2'];
		$newfilename=$_POST['newname'];	
		$newfolderpath="";
		 if($_FILES){
		 
		$hh=$_POST['h'];
		$ww=$_POST['w'];
		$xx1=$_POST['x1'];
		$yy1=$_POST['y1'];
		$xx2=$_POST['x2'];
		$yy2=$_POST['y2'];		
		$newfilename=$_POST['newname'];
		
             /* if no errors and size less than 250kb */
            if (! $_FILES['image']['error'] && $_FILES['image']['size'] < 1300 * 1300) {
                    /* new unique filename */
					$filename = explode('.',$_FILES['image']['name']);
					/* echo BASE_URL; */
                    /* $sTempFileName = 'C:/wamp/www/project1/assets/images/' . $filename[0]; */
					/* if($business_id==1){ */
					/* $sTempFileName = realpath('../assets/images/services')."/".$newfilename; */
					/* echo $sTempFileName; */
					/* }else{ */
					/* $newfoldername=$_POST['id'];  */
						$newfolderpath=realpath('../assets/images/services')."/";
						/* echo "<br> NEw folder name".$newfolderpath; */ 
						if(!file_exists($newfolderpath)){
						mkdir($newfolderpath,0755);						
						}
						$sTempFileName=$newfolderpath.$newfilename;
					/* echo "<br> Temp file nsme ".$sTempFileName; */
					/* } */
                    /*  move uploaded file into cache folder */
                    move_uploaded_file($_FILES['image']['tmp_name'], $sTempFileName);
                    
                      /* if (file_exists($sTempFileName) && filesize($sTempFileName) > 0) { */
                        $aSize = getimagesize($sTempFileName); 
                      if (!$aSize) {
                            @unlink($sTempFileName);
                            return;
                        }
                        /*  check for image type */
                        switch($aSize[2]) {
                            case IMAGETYPE_JPEG:
                                $sExt = '.jpg';
                                /*  create a new image from file */
                                $vImg = @imagecreatefromjpeg($sTempFileName);
                                break;
                            case IMAGETYPE_PNG:
                                $sExt = '.png';
                                /*  create a new image from file */
                                $vImg = @imagecreatefrompng($sTempFileName);
                                break;
                            default:
                                unlink($sTempFileName);
                                return;
                        }
                        /*  create a new true color image */
                        $vDstImg = @imagecreatetruecolor( $iWidth, $iHeight );
                        /*  copy and resize part of an image with resampling */
                        /*  imagecopyresampled($vDstImg, $vImg, 0, 0, (int)$xx1, (int)$yy1, $iWidth, $iHeight, (int)$ww, (int)$hh); */
						imagecopyresampled($vDstImg, $vImg, 0,0, (int)$xx1, (int)$yy1, $iWidth, $iHeight, (int)$ww, (int)$hh);
                        /*  define a result image filename */
                        $sResultFileName = $sTempFileName . $sExt;
                        /*  output image to file */
                        imagejpeg($vDstImg, $sResultFileName, $iJpgQuality);
                        @unlink($sTempFileName);
						/* echo $filename[0].$sExt; */
						echo $newfilename.$sExt;
					}
			}
		}	
	 
?>