How to Crop Image with jQuery and PHP
I have received many requests from my readers to write something on image crop in php, so today I am going to write this tutorial on PHPGang how to crop images with jQuery and PHP. I have used jCrop javascript library to perform this task with PHP its a very easy to implement and very useful for thumbnail generation. Hope you love this tutorial.
[wpdm_file id=26]DEMO
PHP Methods to save image:
<?php $targ_w = $targ_h = 150; $jpeg_quality = 90; $src = 'demo_files/pool.jpg'; $img_r = imagecreatefromjpeg($src); $dst_r = ImageCreateTrueColor( $targ_w, $targ_h ); imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'], $targ_w,$targ_h,$_POST['w'],$_POST['h']); header('Content-type: image/jpeg'); imagejpeg($dst_r,null,$jpeg_quality); ?>
This will simply show image on crop if you want to save that image in some directory then make changes in last two line as below.
//header('Content-type: image/jpeg'); imagejpeg($dst_r,PATH_TO_SAVE_IMAGE,$jpeg_quality);
Javascript Configurations:
<script type="text/javascript"> $(function(){ $(\'#cropbox\').Jcrop({ aspectRatio: 1, onSelect: updateCoords, // minSize:[200,200], start minimum image size // maxSize:[200,200], max size should be... }); }); </script>
Tutorial Categories:
This is an awesome tutorial . It is very useful for me. 🙂
How to crop image in round shape. But It shuld not include the css. I want new image in round shape. Tell me sir
Hello there i am unable to download the source code event after signin
Hi i am not able to download source code even after subscribe
hi, i can’t download source code
I receive this error when I try to save to directory /uploads… Warning: imagejpeg() [function.imagejpeg]: Unable to open ‘/uploads’ for writing: Permission denied in
I am trying to save the image after crop using this line of code:
imagejpeg($dst_r,’/uploads’,$jpeg_quality);
Please help!
Thanks!
The problem is that your folder is not having write permission. And because of that it is not uploading the file.
You have to give it write permission. You can also use chmod for giving write permission to that folder.
same error occurs to me if you got the answer pls reply to my mail id. id: [email protected].
thank you
very nice…….its very helpfull…
Hi,
When i have tried to download the script getting following errors.
/var/www/html/wp-content/plugins/download-manager/cache/ must have to be writable!
Please look into this.
hi, i can’t download source code.please help me.
Hi i am not able to download source code even after subscribe
•
Reply
•
Share ›
hi, i cant download your code .Could you please help me to download this source code.
What a piece of shit.Not working Please mention what all additional scripts you had used.