hoopplaya4 Posted April 8, 2009 Share Posted April 8, 2009 Hi All, I'm currently using jCrop, a jquery tool to crop images. I have no problems cropping the image, however, I'm not sure how I would save the image to a certain directory. Here is my current code which exports the PNG file and displays it, but I'd like to save it to a directory: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $targ_w = $targ_h = 48; $jpeg_quality = 90; $src = 'demo_files/flowers.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'); imagepng($dst_r,null,$png_quality); exit; } ?> Would I need to use fwrite? If so (or if not), how would I implement it into my current code? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/153215-solved-save-image-to-directory-with-gd/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 8, 2009 Share Posted April 8, 2009 Use the 2nd parameter in the imagepng function call. As always, the documentation for what you are doing supplies the answer most of the time - http://us2.php.net/imagepng Quote Link to comment https://forums.phpfreaks.com/topic/153215-solved-save-image-to-directory-with-gd/#findComment-804857 Share on other sites More sharing options...
hoopplaya4 Posted April 8, 2009 Author Share Posted April 8, 2009 Thanks for the reply. Okay, so I've added/modified the code to the following: <?php $save_file = "/home/username/public_html/jcrop/saved"; imagepng($dst_r,$save_file,$jpeg_quality) But, it is not saving to the "saved" folder. This folder is set to 777 permissions. All it does is load the page, and then display the URL: http://www.mydomain.com/jcrop/crop.php (Interestingly, I cannot copy/paste this text. Not sure what I'm doing wrong here. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/153215-solved-save-image-to-directory-with-gd/#findComment-805047 Share on other sites More sharing options...
.josh Posted April 9, 2009 Share Posted April 9, 2009 your $save_file just has the path. Where's the actual filename? Quote Link to comment https://forums.phpfreaks.com/topic/153215-solved-save-image-to-directory-with-gd/#findComment-805124 Share on other sites More sharing options...
hoopplaya4 Posted April 9, 2009 Author Share Posted April 9, 2009 Hey crayonviolent, thanks for the reply. I just figured that out as you were posting. I wasn't giving it a filename. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/153215-solved-save-image-to-directory-with-gd/#findComment-805162 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.