www.webdeveloper.com
Results 1 to 5 of 5

Thread: Image upload crop help

  1. #1
    Join Date
    Oct 2012
    Posts
    15

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

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,221
    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
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jul 2007
    Posts
    386
    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
    Posts
    26
    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
    Location
    localhost
    Posts
    2,290
    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.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

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



Recent Articles