That's my first approach with GD stuff. I'm trying to implement resize and crop using jcrop jquery plugin. I still can't figure out how to save the image I've cropped. On the jcrop site there's not much about it. here's my code:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$targ_w = $targ_h = 150;
$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');
imagejpeg($dst_r,null,$jpeg_quality);
exit;
}
What do I do with imagejpeg($dst_r,null,$jpeg_quality) in order to actually write the image file and save its path in my db?
Thanks in advance.
Mauro
If you want to save the file instead of outputting it, do these two things:
header('Content-type: image/jpeg');
imagejpeg($dst_r, 'path/to/output.jpg', $jpeg_quality);
See the docs for the imagejpeg()
function at php.net/imagejpeg
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.