Created
July 3, 2014 15:13
-
-
Save daliborgogic/ee3ac0b044ed769c5835 to your computer and use it in GitHub Desktop.
crop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$imgUrl = $_POST['imgUrl']; | |
$imgInitW = $_POST['imgInitW']; | |
$imgInitH = $_POST['imgInitH']; | |
$imgW = $_POST['imgW']; | |
$imgH = $_POST['imgH']; | |
$imgY1 = $_POST['imgY1']; | |
$imgX1 = $_POST['imgX1']; | |
$cropW = $_POST['cropW']; | |
$cropH = $_POST['cropH']; | |
$jpeg_quality = 100; | |
$output_filename = "temp/croppedImg_".rand(); | |
$what = getimagesize($imgUrl); | |
switch(strtolower($what['mime'])) | |
{ | |
case 'image/png': | |
$img_r = imagecreatefrompng($imgUrl); | |
$source_image = imagecreatefrompng($imgUrl); | |
$type = '.png'; | |
break; | |
case 'image/jpeg': | |
$img_r = imagecreatefromjpeg($imgUrl); | |
$source_image = imagecreatefromjpeg($imgUrl); | |
$type = '.jpeg'; | |
break; | |
case 'image/gif': | |
$img_r = imagecreatefromgif($imgUrl); | |
$source_image = imagecreatefromgif($imgUrl); | |
$type = '.gif'; | |
break; | |
default: die('image type not supported'); | |
} | |
$resizedImage = imagecreatetruecolor($imgW, $imgH); | |
imagecopyresampled($resizedImage, $source_image, 0, 0, 0, 0, $imgW, | |
$imgH, $imgInitW, $imgInitH); | |
$dest_image = imagecreatetruecolor($cropW, $cropH); | |
imagecopyresampled($dest_image, $resizedImage, 0, 0, $imgX1, $imgY1, $cropW, | |
$cropH, $cropW, $cropH); | |
imagepng($dest_image, $output_filename.$type, 0); | |
$response = array( | |
"status" => 'success', | |
"url" => $output_filename.$type | |
); | |
print json_encode($response); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment