diff options
author | webchick <webchick@24967.no-reply.drupal.org> | 2011-10-17 09:49:19 -0700 |
---|---|---|
committer | webchick <webchick@24967.no-reply.drupal.org> | 2011-10-17 09:49:19 -0700 |
commit | 89ad342620ab99728f64de4a32e4edf6ade55aa0 (patch) | |
tree | 8c8888b525b6f6168a3ebdfa269e24341c276589 /includes | |
parent | 36dfb0797bffc5df535a58ca77eef9eb65e4ced8 (diff) | |
download | brdo-89ad342620ab99728f64de4a32e4edf6ade55aa0.tar.gz brdo-89ad342620ab99728f64de4a32e4edf6ade55aa0.tar.bz2 |
Oops. Forgot a file.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/image.inc | 77 |
1 files changed, 57 insertions, 20 deletions
diff --git a/includes/image.inc b/includes/image.inc index b04943b5e..8dc36b995 100644 --- a/includes/image.inc +++ b/includes/image.inc @@ -160,7 +160,7 @@ function image_get_info($filepath, $toolkit = FALSE) { * The target height, in pixels. * * @return - * TRUE or FALSE, based on success. + * TRUE on success, FALSE on failure. * * @see image_load() * @see image_resize() @@ -178,12 +178,13 @@ function image_scale_and_crop(stdClass $image, $width, $height) { } /** - * Scales an image to the given width and height while maintaining aspect ratio. + * Scales image dimensions while maintaining aspect ratio. * - * The resulting image can be smaller for one or both target dimensions. + * The resulting dimensions can be smaller for one or both target dimensions. * - * @param $image - * An image object returned by image_load(). + * @param $dimensions + * Dimensions to be modified - an array with components width and height, in + * pixels. * @param $width * The target width, in pixels. This value is omitted then the scaling will * based only on the height value. @@ -195,13 +196,12 @@ function image_scale_and_crop(stdClass $image, $width, $height) { * up. This generally results in a low quality image. * * @return - * TRUE or FALSE, based on success. + * TRUE if $dimensions was modified, FALSE otherwise. * - * @see image_load() - * @see image_scale_and_crop() + * @see image_scale() */ -function image_scale(stdClass $image, $width = NULL, $height = NULL, $upscale = FALSE) { - $aspect = $image->info['height'] / $image->info['width']; +function image_dimensions_scale(array &$dimensions, $width = NULL, $height = NULL, $upscale = FALSE) { + $aspect = $dimensions['height'] / $dimensions['width']; if ($upscale) { // Set width/height according to aspect ratio if either is empty. @@ -214,19 +214,56 @@ function image_scale(stdClass $image, $width = NULL, $height = NULL, $upscale = $height = !empty($height) ? $height : 9999999; // Don't scale up. - if (round($width) >= $image->info['width'] && round($height) >= $image->info['height']) { - return TRUE; + if (round($width) >= $dimensions['width'] && round($height) >= $dimensions['height']) { + return FALSE; } } if ($aspect < $height / $width) { - $height = $width * $aspect; + $dimensions['width'] = $width; + $dimensions['height'] = (int) round($width * $aspect); } else { - $width = $height / $aspect; + $dimensions['width'] = (int) round($height / $aspect); + $dimensions['height'] = $height; + } + + return TRUE; +} + +/** + * Scales an image while maintaining aspect ratio. + * + * The resulting image can be smaller for one or both target dimensions. + * + * @param $image + * An image object returned by image_load(). + * @param $width + * The target width, in pixels. This value is omitted then the scaling will + * based only on the height value. + * @param $height + * The target height, in pixels. This value is omitted then the scaling will + * based only on the width value. + * @param $upscale + * Boolean indicating that files smaller than the dimensions will be scaled + * up. This generally results in a low quality image. + * + * @return + * TRUE on success, FALSE on failure. + * + * @see image_dimensions_scale() + * @see image_load() + * @see image_scale_and_crop() + */ +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, $width, $height); + return image_resize($image, $dimensions['width'], $dimensions['height']); } /** @@ -240,7 +277,7 @@ function image_scale(stdClass $image, $width = NULL, $height = NULL, $upscale = * The target height, in pixels. * * @return - * TRUE or FALSE, based on success. + * TRUE on success, FALSE on failure. * * @see image_load() * @see image_gd_resize() @@ -267,7 +304,7 @@ function image_resize(stdClass $image, $width, $height) { * be white. * * @return - * TRUE or FALSE, based on success. + * TRUE on success, FALSE on failure. * * @see image_load() * @see image_gd_rotate() @@ -291,7 +328,7 @@ function image_rotate(stdClass $image, $degrees, $background = NULL) { * The target height, in pixels. * * @return - * TRUE or FALSE, based on success. + * TRUE on success, FALSE on failure. * * @see image_load() * @see image_scale_and_crop() @@ -315,7 +352,7 @@ function image_crop(stdClass $image, $x, $y, $width, $height) { * An image object returned by image_load(). * * @return - * TRUE or FALSE, based on success. + * TRUE on success, FALSE on failure. * * @see image_load() * @see image_gd_desaturate() @@ -379,7 +416,7 @@ function image_load($file, $toolkit = FALSE) { * original image file will be overwritten. * * @return - * TRUE or FALSE, based on success. + * TRUE on success, FALSE on failure. * * @see image_load() * @see image_gd_save() |