0

I'm using Jcrop to allow me to crop an uploaded image to be a users avatar.

Essentially I'm having trouble with getting the image info from the 'Content-type: image/jpeg' header once the image has been cropped and posted using this form:

<img src='*userimage*' id='cropbox' />
<form action='crop.php' method='post' onsubmit='return checkCoords();'>
<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' value='Crop Image' />
</form>

The page this posts to only has this code:

<?php

$targ_w = $targ_h = 150;
$jpeg_quality = 90;

$src = 'userimages/63/63.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);
?>

This shows the cropped image which is great, but I don't want it posted to the crop.php page like this. I would like to be able to include my site header/footer/style etc and display the cropped image as a filename, so i can then have it approved by the user and saved to their appropriate folder.

Can anyone help?

Thanks

Dan
  • 977
  • 6
  • 16
  • 31

1 Answers1

0

I've figured this out simply by commenting out the Header and specifying the path to save to:

//header('Content-type: image/jpeg');
imagejpeg($dst_r,"userimages/$user_id/$user_id.jpg",$jpeg_quality);
// Remove from memory
imagedestroy($dst_r);
Dan
  • 977
  • 6
  • 16
  • 31