/    Sign up×
Community /Pin to ProfileBookmark

Image upload crop help

I’m using a function to crop an image when I upload a image into a folder to certain pixels that I want to set up

and I upload the image and its not cropping the image

here is the function that I’m using to crop the image

help?

function ak_img_resize($target, $newcopy, $w, $h, $ext) {
list($w_orig, $h_orig) = getimagesize($target);
$scale_ratio = $w_orig / $h_orig;
if (($w / $h) > $scale_ratio) {
$w = $h * $scale_ratio;
} else {
$h = $w / $scale_ratio;
}
$img = “”;
$ext = strtolower($ext);
if ($ext == “gif”){
$img = imagecreatefromgif($target);
} else if($ext ==”png”){
$img = imagecreatefrompng($target);
} else {
$img = imagecreatefromjpeg($target);
}
$tci = imagecreatetruecolor($w, $h);
// imagecopyresampled(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
if ($ext == “gif”){
imagegif($tci, $newcopy);
} else if($ext ==”png”){
imagepng($tci, $newcopy);
} else {
imagejpeg($tci, $newcopy, 84);
}
}

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 02.2012 — Here's something I wrote (quite some time ago now) you might want to play around with: http://www.charles-reace.com/blog/?s=image+resize+crop
Copy linkTweet thisAlerts:
@SparoHawkNov 02.2012 — There are tons of libraries for handling image out there. Wouldn't hurt to check them out. You can try phpclasses.org.
Copy linkTweet thisAlerts:
@danny_roughAug 12.2013 — I use an imaging sdk found on the internet which can [COLOR="#000000"]crop images[/COLOR] found on the internet . Install it and it becomes a selectable processing option.Then you can crop images in any program at all, including Adobe Acrobat . Just open the images, select crop ,and follow the setps given in the sdk, the task will be finished in several seconds. if you haven't found a good choice , you can have a try. best wishes.
Copy linkTweet thisAlerts:
@rootAug 13.2013 — You need to know what size you want the image to be able to calculate the ratio.

You are taking the original height and width and creating a ratio from its aspect which bears no relationship to the size you are trying to crop to.

With sizes that you want your image to be your use the height and width to perform calculation against the uploaded image so you know how much you have to reduce the original by.

You might want to look at some of the available scripts online that produce thumbnails from images in folders.
×

Success!

Help @A123Schmidt 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.17,
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,
)...