function image_scale in Drupal 7
Same name and namespace in other branches
- 4 includes/image.inc \image_scale()
- 5 includes/image.inc \image_scale()
- 6 includes/image.inc \image_scale()
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
3 calls to image_scale()
- file_validate_image_resolution in includes/
file.inc - Verifies that image dimensions are within the specified maximum and minimum.
- ImageToolkitUnitTest::testScale in modules/
simpletest/ tests/ image.test - Test the image_scale() function.
- image_scale_effect in modules/
image/ image.effects.inc - Image effect callback; Scale an image resource.
4 string references to 'image_scale'
- hook_image_default_styles in modules/
image/ image.api.php - Provide module-based image styles for reuse throughout Drupal.
- ImageAdminStylesUnitTest::testDefaultStyle in modules/
image/ image.test - Test to override, edit, then revert a style.
- ImageDimensionsTestCase::testImageDimensions in modules/
image/ image.test - Test styled image dimensions cumulatively.
- image_image_default_styles in modules/
image/ image.module - Implements hook_image_default_styles().
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']);
}