--- image.inc +++ (clipboard) @@ -168,6 +168,24 @@ * @param $height The target height */ function image_crop($source, $destination, $x, $y, $width, $height) { + $info = image_get_info($source); + if (!$info) { + return FALSE; + } + + // don't crop if smaller than dimensions provided + if ($width >= $info['width'] && $height >= $info['height']) { + return FALSE; + } + + if ($width >= $info['width'] && $height < $info['height']) { + $width = $info['width']; + } + + if ($width < $info['width'] && $height >= $info['height']) { + $height = $info['height']; + } + return image_toolkit_invoke('crop', array($source, $destination, $x, $y, $width, $height)); } @@ -285,6 +303,19 @@ return FALSE; } + // don't crop if smaller than dimensions provided + if ($width >= $info['width'] && $height >= $info['height']) { + return FALSE; + } + + if ($width >= $info['width'] && $height < $info['height']) { + $width = $info['width']; + } + + if ($width < $info['width'] && $height >= $info['height']) { + $height = $info['height']; + } + $im = image_gd_open($source, $info['extension']); $res = imageCreateTrueColor($width, $height); imageCopy($res, $im, 0, 0, $x, $y, $width, $height);