Jump to content

[SOLVED] Save Image to Directory with GD


hoopplaya4

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/153215-solved-save-image-to-directory-with-gd/
Share on other sites

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.