Forum Moderators: coopster

Message Too Old, No Replies

imagecopyresampled then upload

upload an image, crop then upload result

         

Robert Poole

4:12 pm on Jan 9, 2009 (gmt 0)

10+ Year Member



Happy New Year everyone.

Okay, so here's my dilemma of the day. I'm using a jQuery image crop feature, and what I want to do is upload an image, crop it, then take the result and upload that (then delete the original).

I have no problems uploading the original picture to a temporary folder "temp" and the preview all looks fine, and under that sits this form:

<form action="upload.php" method="post" onSubmit="return checkCoords();">
<input type="hidden" id="img" name="img" value="<?php echo $path_name; ?>" />
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
<input type="submit" name="Crop" value="Crop Image" class="submit" />
</form>

That gets sent to this page:

<?php
$targ_w = $targ_h = 150;
$jpeg_quality = 90;

$src = $_POST['img'];
$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;

?>

But what I get is a 150x150 black square. That's problem #1. Problem #2 would be how do I upload the resulting 150x150 image?

Any help would be appreciated.

Roberto.

eelixduppy

9:11 pm on Jan 17, 2009 (gmt 0)



How you doing with this? Not sure about the black square but to save the image you have to do just that, save it (write it) to a file in the place you want.