Image cropping in PHP is producing blank result

Posted by thinkswan on Stack Overflow See other posts from Stack Overflow or by thinkswan
Published on 2010-03-28T00:33:55Z Indexed on 2010/03/28 0:43 UTC
Read the original article Hit count: 629

Filed under:
|
|
|

I'm simply trying to crop a JPEG image (no scaling) using PHP. Here is my function, along with the inputs.

function cropPicture($imageLoc, $width, $height, $x1, $y1) {
    $newImage = imagecreatetruecolor($width, $height);

    $source = imagecreatefromjpeg($imageLoc);
    imagecopyresampled($newImage,$source,0,0,$x1,$y1,$width,$height,$width,$height);
    imagejpeg($newImage,$imageLoc,90);
}

When I call it as follows--cropPicture('image.jpg', 300, 300, 0, 0)--the function completes properly, but I'm left with a black image that is 300x300 px (in other words, a blank canvas). Am I passing in the wrong arguments?

The image exists and is writeable.

© Stack Overflow or respective owner

Related posts about php

Related posts about gd