| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 
 | 	// DEFINE VARIABLES
	$imageWidth			 = $_POST['imageWidth'];
	$imageHeight		 = $_POST['imageHeight'];
	$imageFileName		 = $_POST['imageFileName'];
	$cropX				 = $_POST['cropX'];
	$cropY				 = $_POST['cropY'];
	$cropWidth			 = $_POST['cropWidth'];
	$cropHeight			 = $_POST['cropHeight'];
 
	if($cropWidth == 0) { $cropWidth = $imageWidth; }
	if($cropHeight == 0) { $cropHeight = $imageHeight; }
 
	$sourceFile			 = "../files/working/uploads/". $imageFileName;
	$destinationFile = "../files/working/cropped/" . $imageFileName;
 
	if(file_exists($destinationFile)) { chmod($destinationFile, 0777); unlink($destinationFile); }
 
	// CHECK TO SEE IF WE NEED TO CROP
	if($imageWidth != $cropWidth || $imageHeight != $cropHeight) {
		$canvas = imagecreatetruecolor($cropWidth,$cropHeight);
		$piece = imagecreatefromjpeg($sourceFile);
		imagecopy($canvas,$piece,0,0,$cropX,$cropY,$cropWidth,$cropHeight);
		imagejpeg($canvas,$destinationFile,90);
		imagedestroy($canvas);
		imagedestroy($piece);
		chmod($destinationFile, 0777);
 
	} else {
		// CROP WAS SKIPPED -- MOVE TO CROPPED FOLDER ANYWAY	
		copy($sourceFile,$destinationFile);
		chmod($destinationFile, 0777);
	} | 
Partager