Results 1 to 5 of 5

Thread: Image upload crop help

  1. #1
    Join Date
    Oct 2012

    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


    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);

  2. #2
    Join Date
    Aug 2004
    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
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Jul 2007
    There are tons of libraries for handling image out there. Wouldn't hurt to check them out. You can try phpclasses.org.

  4. #4
    Join Date
    Apr 2013
    I use an imaging sdk found on the internet which can crop images 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.

  5. #5
    Join Date
    Mar 2007
    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.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center