I am using Jcrop plugin to crop an image.
I upload my photo with a standard html form.
I show my last uploaded image with the following code:
<img id="cropbox" src="<?php echo $target ?>" width="400" />
This looks like the following:
My code for $target looks like this:
<?php
$target = "uploads/";
$target = $target . basename( $_FILES['filename']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['filename']['tmp_name'], $target))
{
echo "De afbeelding *". basename( $_FILES['filename']['name']). "* is geupload naar de map 'uploads'";
}
else {
echo "Sorry, er is een probleem met het uploaden van de afbeelding.";
}
?>
Now i can start selecting my area to crop:
Now i want to save the selected crop area to a new jpg image using the following code:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$targ_w = 200;
$targ_h = 400;
$jpeg_quality = 90;
$src = '';
$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;
}
?>
My question is now, how do i use that $target Source i used to show the image i just uploaded in that php code above?
I have no idea.
You can put the path to file into $_SESSION when uploading the target. In your uploaded.php use this code (here you start the session with session_start() and put the formed target path to $_SESSION array):
In your crop.php: