function image_scale
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
Related topics
File
- includes/image.inc, line 252
- 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']); }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!image.inc/function/image_scale/7.x