? 367484_allow_upcrop.patch
Index: imagecache_actions.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache_actions.inc,v
retrieving revision 1.24.2.3
diff -u -p -r1.24.2.3 imagecache_actions.inc
--- imagecache_actions.inc 19 Aug 2009 21:05:31 -0000 1.24.2.3
+++ imagecache_actions.inc 27 May 2010 22:00:17 -0000
@@ -152,6 +152,8 @@ function imagecache_crop_form($data = ar
'height' => '',
'xoffset' => '',
'yoffset' => '',
+ 'width_upcrop' => 1,
+ 'height_upcrop' => 1
);
$form['width'] = array(
'#type' => 'textfield',
@@ -177,20 +179,56 @@ function imagecache_crop_form($data = ar
'#default_value' => $data['yoffset'],
'#description' => t('Enter an offset in pixels or use a keyword: top, center, or bottom.'),
);
+ $form['width_upcrop'] = array(
+ '#type' => 'checkbox',
+ '#default_value' => (isset($data['width_upcrop'])) ? $data['width_upcrop'] : 0,
+ '#title' => t('Allow width upcropping'),
+ '#description' => t('Let crop make images wider than their original size'),
+ );
+ $form['height_upcrop'] = array(
+ '#type' => 'checkbox',
+ '#default_value' => (isset($data['height_upcrop'])) ? $data['height_upcrop'] : 0,
+ '#title' => t('Allow height upcropping'),
+ '#description' => t('Let crop make images taller than their original size'),
+ );
return $form;
}
function theme_imagecache_crop($element) {
$data = $element['#value'];
- return t('width: @width, height: @height, xoffset: @xoffset, yoffset: @yoffset', array(
+ // The check for is helps with upgrades where upcropping was default.
+ if (!isset($data['width_upcrop']) || ($data['width_upcrop'] && $data['height_upcrop'])) {
+ $upcrop = t('width and height upcropping');
+ }
+ elseif ($data['height_upcrop']) {
+ $upcrop = t('height upcropping');
+ }
+ elseif ($data['width_upcrop']) {
+ $upcrop = t('width upcropping');
+ }
+ else {
+ $upcrop = t('no upcrop');
+ }
+
+ return t('width: @width, height: @height, xoffset: @xoffset, yoffset: @yoffset (@upcrop)', array(
'@width' => $data['width'],
'@height' => $data['height'],
'@xoffset' => $data['xoffset'],
'@yoffset' => $data['yoffset'],
+ '@upcrop' => $upcrop,
));
}
function imagecache_crop_image(&$image, $data) {
+ // Check to see if they have upcropping enabled and if it would happen
+ // and then change the specified crop size to an appropriate value.
+ if (isset($data['height_upcrop']) && !$data['height_upcrop'] && $image->info['height'] < $data['height']) {
+ $data['height'] = $image->info['height'];
+ }
+ if (isset($data['width_upcrop']) && !$data['width_upcrop'] && $image->info['width'] < $data['width']) {
+ $data['width'] = $image->info['width'];
+ }
+
if (!imageapi_image_crop($image, $data['xoffset'], $data['yoffset'], $data['width'], $data['height'])) {
watchdog('imagecache', 'imagecache_crop failed. image: %image, data: %data.', array('%image' => $image->source, '%data' => print_r($data, TRUE)), WATCHDOG_ERROR);
return FALSE;