Scales an image while maintaining aspect ratio.
The resulting image can be smaller for one or both target dimensions.
object $image: An image object returned by image_load().
int $width: (optional) The target width, in pixels. This value is omitted then the scaling will based only on the height value.
int $height: (optional) The target height, in pixels. This value is omitted then the scaling will based only on the width value.
bool $upscale: (optional) Boolean indicating that files smaller than the dimensions will be scaled up. This generally results in a low quality image.
bool TRUE on success, FALSE on failure.
function image_scale($image, $width = NULL, $height = NULL, $upscale = FALSE) {
$dimensions = $image->info;
// Scale the dimensions - if they don't change then just return success.
if (!image_dimensions_scale($dimensions, $width, $height, $upscale)) {
return TRUE;
}
return image_resize($image, $dimensions['width'], $dimensions['height']);
}