I have some upload form for images. I want to crop images automatically. And on submit save cropped images.
<input type="file" id="file" name="files[]" multiple/>
I want to crop image: example 800x600, but from center of image, not from corners.
Just upload the file normally. Then, this should do the trick:
$filename = "LINK TO IMAGE";
// Get dimensions of the coriginal image
list($width, $height) = getimagesize($filename);
// Resample the image
$canvas = imagecreatetruecolor('800', '600');
$current_image = imagecreatefromjpeg($filename);
imagecopy($canvas, $current_image, 0, 0, $width/2, $height/2, '800', '600');
imagejpeg($canvas, $filename.'_cropped.jpg', 100);
chmod($filename.'_cropped.jpg', 0644);
unlink($filename);
I did not test the above code. In case of errors please add a comment and I'll help.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments