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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.