I figured (or threw together) a pretty nice image cropping tool, please go to http://miamiproviders.com/providers/test_feature.php?id=1
select an image and submit the form
it takes yu to the cropping thing which is great. But, whenI try to save the cropped image, it doesn’t, heres what I have so far but is not working
$dirname = "images/".$_GET['id']."/";
$max_width = "500"; // Max width allowed for the large image
$thumb_width = "100"; // Width of thumbnail image
$thumb_height = "100"; // Height of thumbnail image
//Image Locations
$large_image_location = "{$dirname}temp.jpg";
$thumb_image_location = "{dirfname}feature.jpg";
function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
$newImageWidth = ceil($width * $scale);
$newImageHeight = ceil($height * $scale);
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
$source=imagecreatefromjpeg($image);
imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
imagejpeg($newImage,$thumb_image_name,90);
}
if (isset($_POST["upload_thumbnail"])) {
//echo "<pre>";print_r($_POST);echo "</pre>";
//Get the new coordinates to crop the image.
$x1 = $_POST["x1"];
$y1 = $_POST["y1"];
$x2 = $_POST["x2"];
$y2 = $_POST["y2"];
$w = $_POST["w"];
$h = $_POST["h"];
//Scale the image to the thumb_width set above
$scale = $thumb_width/$w;
$cropped = resizeThumbnailImage($thumb_image_location, $large_image_location,$w,$h,$x1,$y1,$scale);
}
I think you had some typos (capatilized letters) in there, is this right
if (isset($_POST["upload_thumbnail"])) {
//echo "<pre>";print_r($_POST);echo "</pre>";
//Get the new coordinates to crop the image.
$x1 = $_POST["x1"];
$y1 = $_POST["y1"];
$x2 = $_POST["x2"];
$y2 = $_POST["y2"];
$w = $_POST["w"];
$h = $_POST["h"];
//Scale the image to the thumb_width set above
$scale = $thumb_width/$w;
$cropped = resizeThumbnailImage($thumb_image_location, $large_image_location,$w,$h,$x1,$y1,$scale);
echo $cropped;
// Save the image as a jpg
imagejpeg( $cropped, $dirname."feature.jpg" );
// Clear the memory of the tempory image
imagedestroy( $cropped );
}
i tried it again (am trying to understand the php
I created another cropping tool, http://miamiproviders.com/cropimages/?id=1
So I guess everything is working except the PHP part which saves the new image, heres that script)
I like this method cause this allows me to crop an ikmagfe on the fly (the other way I had to make a duplicate of the image to be cropped which was a mess for me.