/    Sign up×
Community /Pin to ProfileBookmark

saving a cropped image

I used javascript to crop an image,
[url]http://miamiproviders.com/providers/test_feature.php?id=1[/url]
Select an image, submit the form and thats the cool cropping thing.
The next step is to save the new cropped image (as feature.jpg) into the folder ($dirname points to it) This is what I have soo far,

[code=php]
$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,$image,90);
}
function getHeight($image) {
$size = getimagesize($image);
$height = $size[1];
return $height;
}
function getWidth($image) {
$size = getimagesize($image);
$width = $size[0];
return $width;
}
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 );
}
[/code]

I am stumped as I thought if I echo $cropped I would get the path to the cropped image, but it shows nothing…
What am I missing?

Thanks.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @lukeurtnowski spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...