function image_scale

Scales an image while maintaining aspect ratio.

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

Parameters

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.

Return value

bool TRUE on success, FALSE on failure.

See also

image_dimensions_scale()

image_load()

image_scale_and_crop()

Related topics

3 calls to image_scale()
file_validate_image_resolution in drupal/core/modules/file/file.module
Verifies that image dimensions are within the specified maximum and minimum.
image_scale_effect in drupal/core/modules/image/image.effects.inc
Image effect callback; Scale an image resource.
ToolkitTest::testScale in drupal/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php
Test the image_scale() function.
7 string references to 'image_scale'
ConfigSchemaTest::testSchemaData in drupal/core/modules/config/lib/Drupal/config/Tests/ConfigSchemaTest.php
Tests metadata applied to configuration objects.
image.style.large.yml in drupal/core/modules/image/config/image.style.large.yml
drupal/core/modules/image/config/image.style.large.yml
image.style.medium.yml in drupal/core/modules/image/config/image.style.medium.yml
drupal/core/modules/image/config/image.style.medium.yml
image.style.thumbnail.yml in drupal/core/modules/image/config/image.style.thumbnail.yml
drupal/core/modules/image/config/image.style.thumbnail.yml
ImageAdminStylesTest::testEditEffect in drupal/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php
Verifies that editing an image effect does not cause it to be duplicated.

... See full list

File

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

Code

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