Javascript Image Cropper with Mootools and PHP
MooCrop is a library which can be used to create a cropping interface in your webpage. With this library after a crop region is selected a php script can be called to crop the image on serverside. The moocrop interface provides four values that is the width , height , left and top of the crop region ; these values can be used by a php script to crop an image.
So these values can be obtained in the script like this :
$x = $_GET['x'];
$y = $_GET['y'];
$h = $_GET['h'];
$w = $_GET['w'];
For e.g. if its a jpg image then
$src = imagecreatefromjpeg($path);
where $path has the path to the image.
Now create a new image with height and width
$dest = imagecreatetruecolor($w, $h);
imagecopy($dest, $src, 0, 0, $x, $y, $w, $h);
Now overwrite the existing file :
imagejpeg($dest , $path);
You may need to do a chmod over the new file.
chmod($path , 0755);
Free memory
imagedestroy($dest);
imagedestroy($src);
Now $path is the new image which is cropped as per the values of x , y , h , w
Popularity: 2% [?]















