You are here

function image_scale_effect in Drupal 7

Image effect callback; Scale an image resource.

Parameters

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

$data: An array of attributes to use when performing the scale effect with the following items:

  • "width": An integer representing the desired width in pixels.
  • "height": An integer representing the desired height in pixels.
  • "upscale": A boolean indicating that the image should be upscaled if the dimensions are larger than the original image.

Return value

TRUE on success. FALSE on failure to scale image.

See also

image_scale()

1 call to image_scale_effect()
ImageEffectsUnitTest::testScaleEffect in modules/image/image.test
Test the image_scale_effect() function.
1 string reference to 'image_scale_effect'
image_image_effect_info in modules/image/image.effects.inc
Implements hook_image_effect_info().

File

modules/image/image.effects.inc, line 124
Functions needed to execute image effects provided by Image module.

Code

function image_scale_effect(&$image, $data) {

  // Set sane default values.
  $data += array(
    'width' => NULL,
    'height' => NULL,
    'upscale' => FALSE,
  );
  if (!image_scale($image, $data['width'], $data['height'], $data['upscale'])) {
    watchdog('image', 'Image scale failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array(
      '%toolkit' => $image->toolkit,
      '%path' => $image->source,
      '%mimetype' => $image->info['mime_type'],
      '%dimensions' => $image->info['width'] . 'x' . $image->info['height'],
    ), WATCHDOG_ERROR);
    return FALSE;
  }
  return TRUE;
}