-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcrop.php
More file actions
32 lines (27 loc) · 834 Bytes
/
crop.php
File metadata and controls
32 lines (27 loc) · 834 Bytes
1
2
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
<?
// get variables
$imgfile = $_GET['image'];
$cropStartX = $_GET['cropStartX'];
$cropStartY = $_GET['cropStartY'];
$cropW = $_GET['cropWidth'];
$cropH = $_GET['cropHeight'];
$crop = $_GET['crop'];
// Create two images
$origimg = imagecreatefromjpeg($imgfile);
$cropimg = imagecreatetruecolor($cropW, $cropH);
// Get the original size
list($width, $height) = getimagesize($imgfile);
// Crop
imagecopyresized($cropimg, $origimg, 0, 0, $cropStartX, $cropStartY, $width, $height, $width, $height);
$dest = "photo_temp/cropped_photo/";
$crop = $dest.substr($crop, strrpos($crop, '/') + 1);
$ext = substr($crop, strrpos($crop, '.') + 1);
if ($ext == "jpg" || $ext == "jpeg") {
imagejpeg($cropimg, $crop);
} else if ($ext == "png") {
imagepng($cropimg, $crop);
}
echo $crop;
imagedestroy($cropimg);
imagedestroy($origimg);
?>