1 image.inc image_scale(stdClass $image, $width = NULL, $height = NULL, $upscale = FALSE)

Scales an image while maintaining aspect ratio.

The resulting image can be smaller for one or both target dimensions.

Parameters

$image: An image object returned by image_load().

$width: The target width, in pixels. If this value is NULL then the scaling will be based only on the height value.

$height: The target height, in pixels. If this value is NULL then the scaling will be based only on the width value.

$upscale: Boolean indicating that files smaller than the dimensions will be scaled up. This generally results in a low quality image.

Return value

TRUE on success, FALSE on failure.:

See also

image_dimensions_scale()

image_load()

image_scale_and_crop()

Related topics

File

core/includes/image.inc, line 283
API for manipulating images.

Code

function image_scale(stdClass $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']);
}