diff --git a/includes/image.inc b/includes/image.inc index b04943b..1e3be2b 100644 --- a/includes/image.inc +++ b/includes/image.inc @@ -166,8 +166,13 @@ function image_get_info($filepath, $toolkit = FALSE) { * @see image_resize() * @see image_crop() */ -function image_scale_and_crop(stdClass $image, $width, $height) { +function image_scale_and_crop(stdClass $image, $width, $height, $upscale = TRUE) { $scale = max($width / $image->info['width'], $height / $image->info['height']); + if (!$upscale && $scale >= 1.0) { + $width = $width / $scale; + $height = $height / $scale; + $scale = 1.0; + } $x = ($image->info['width'] * $scale - $width) / 2; $y = ($image->info['height'] * $scale - $height) / 2; diff --git a/modules/image/image.admin.inc b/modules/image/image.admin.inc index d72fdf4..01b32ad 100644 --- a/modules/image/image.admin.inc +++ b/modules/image/image.admin.inc @@ -497,7 +497,7 @@ function image_effect_scale_validate($element, &$form_state) { /** * Form structure for the image resize form. * - * Note that this is not a complete form, it only contains the portion of the + * Note that this is not a complete form; it only contains the portion of the * form for configuring the resize options. Therefore it does not not need to * include metadata about the effect, nor a submit button. * @@ -531,8 +531,8 @@ function image_resize_form($data) { /** * Form structure for the image scale form. * - * Note that this is not a complete form, it only contains the portion of the - * form for configuring the scale options. Therefore it does not not need to + * Note that this is not a complete form; it only contains the portion of the + * form for configuring the scale options. Therefore it does not need to * include metadata about the effect, nor a submit button. * * @param $data @@ -553,6 +553,27 @@ function image_scale_form($data) { } /** + * Form structure for the image scale and crop form. + * + * Note that this is not a complete form, it only contains the portion of the + * form for configuring the scale and crop options. Therefore it does not + * need to include metadata about the effect, nor a submit button. + * + * @param $data + * The current configuration for this scale and crop effect. + */ +function image_scale_and_crop_form($data) { + $form = image_resize_form($data); + $form['upscale'] = array( + '#type' => 'checkbox', + '#default_value' => (isset($data['upscale'])) ? $data['upscale'] : TRUE, + '#title' => t('Allow upscaling'), + '#description' => t('Let scale make images larger than their original size'), + ); + return $form; +} + +/** * Form structure for the image crop form. * * Note that this is not a complete form, it only contains the portion of the @@ -880,6 +901,23 @@ function theme_image_scale_summary($variables) { } /** + * Returns HTML for a summary of an image scale and crop effect. + * + * @param $variables + * An associative array containing: + * - data: The current configuration for this scale and crop effect. + * + * @ingroup themeable + */ +function theme_image_scale_and_crop_summary($variables) { + $data = $variables['data']; + if (!isset($data['upscale'])) { + $data['upscale'] = TRUE; + } + return theme('image_resize_summary', array('data' => $data)) . ' ' . ($data['upscale'] ? '(' . t('upscaling allowed') . ')' : ''); +} + +/** * Returns HTML for a summary of an image crop effect. * * @param $variables diff --git a/modules/image/image.effects.inc b/modules/image/image.effects.inc index 122af6c..6b3748b 100644 --- a/modules/image/image.effects.inc +++ b/modules/image/image.effects.inc @@ -28,8 +28,8 @@ function image_image_effect_info() { 'label' => t('Scale and crop'), 'help' => t('Scale and crop will maintain the aspect-ratio of the original image, then crop the larger dimension. This is most useful for creating perfectly square thumbnails without stretching the image.'), 'effect callback' => 'image_scale_and_crop_effect', - 'form callback' => 'image_resize_form', - 'summary theme' => 'image_resize_summary', + 'form callback' => 'image_scale_and_crop_form', + 'summary theme' => 'image_scale_and_crop_summary', ), 'image_crop' => array( 'label' => t('Crop'), @@ -163,7 +163,10 @@ function image_crop_effect(&$image, $data) { * @see image_scale_and_crop() */ function image_scale_and_crop_effect(&$image, $data) { - if (!image_scale_and_crop($image, $data['width'], $data['height'])) { + if (!isset($data['upscale'])) { + $data['upscale'] = TRUE; + } + if (!image_scale_and_crop($image, $data['width'], $data['height'], $data['upscale'])) { watchdog('image', 'Image scale and crop 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; } diff --git a/modules/image/image.module b/modules/image/image.module index d2d081c..65b0912 100644 --- a/modules/image/image.module +++ b/modules/image/image.module @@ -210,6 +210,9 @@ function image_theme() { 'image_scale_summary' => array( 'variables' => array('data' => NULL), ), + 'image_scale_and_crop_summary' => array( + 'variables' => array('data' => NULL), + ), 'image_crop_summary' => array( 'variables' => array('data' => NULL), ),