From e8c7cf9f69e421bceabd9dd12ca35cfe6b392d79 Mon Sep 17 00:00:00 2001 From: andrew morton Date: Wed, 19 Aug 2009 21:05:23 +0000 Subject: [PATCH] SA-CONTRIB-2009-051 --- imagecache.module | 35 ----------------------- imagecache_actions.inc | 73 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 58 insertions(+), 50 deletions(-) diff --git a/imagecache.module b/imagecache.module index 76419ab..86ce71f 100644 --- a/imagecache.module +++ b/imagecache.module @@ -716,41 +716,6 @@ function theme_imagecache($namespace, $path, $alt = '', $title = '', $attributes } - -/************************************************************************************ - * ImageCache action implementation example in module. - */ -function imagecache_resize_image(&$image, $data) { - if (!imageapi_image_resize($image, $data['width'], $data['height'])) { - watchdog('imagecache', t('imagecache_resize_image failed. image: %image, data: %data.', array('%path' => $image, '%data' => print_r($data, true))), WATCHDOG_ERROR); - return false; - } - return true; -} - -function imagecache_resize_form($action) { - $form['width'] = array( - '#type' => 'textfield', - '#title' => t('Width'), - '#default_value' => $action['width'], - '#description' => t('Enter a width in pixels or as a percentage. i.e. 500 or 80%.'), - ); - $form['height'] = array( - '#type' => 'textfield', - '#title' => t('Height'), - '#default_value' => $action['height'], - '#description' => t('Enter a height in pixels or as a percentage. i.e. 500 or 80%.'), - ); - return $form; -} - -function theme_imagecache_resize($element) { - $data = $element['#value']; - return 'width: '. $data['width'] .', height: '. $data['height']; -} - - - /** * ImageCache 2.x API * diff --git a/imagecache_actions.inc b/imagecache_actions.inc index bac3617..c7f815c 100644 --- a/imagecache_actions.inc +++ b/imagecache_actions.inc @@ -2,6 +2,43 @@ // $Id$ /** + * ImageCache Resize + */ +function imagecache_resize_image(&$image, $data) { + if (!imageapi_image_resize($image, $data['width'], $data['height'])) { + watchdog('imagecache', t('imagecache_resize_image failed. image: %image, data: %data.', array('%path' => $image, '%data' => print_r($data, true))), WATCHDOG_ERROR); + return false; + } + return true; +} + +function imagecache_resize_form($action) { + $form['width'] = array( + '#type' => 'textfield', + '#title' => t('Width'), + '#default_value' => $action['width'], + '#description' => t('Enter a width in pixels or as a percentage. i.e. 500 or 80%.'), + ); + $form['height'] = array( + '#type' => 'textfield', + '#title' => t('Height'), + '#default_value' => $action['height'], + '#description' => t('Enter a height in pixels or as a percentage. i.e. 500 or 80%.'), + ); + return $form; +} + +function theme_imagecache_resize($element) { + $data = $element['#value']; + if ($data['width'] && $data['height']) { + return check_plain($data['width']) . 'x' . check_plain($data['height']); + } + return ($data['width']) ? t('width @width', array('@width' => $data['width'])) : t('height @height', array('@height' => $data['height'])); +} + + + +/** * Imagecache Scale */ function imagecache_scale_form($data) { @@ -16,9 +53,7 @@ function imagecache_scale_form($data) { } function theme_imagecache_scale($element) { - $output = theme_imagecache_resize($element) . ', upscale: '. - $output .= ($element['#value']['upscale']) ? t('Yes') : t('No'); - return $output; + return theme_imagecache_resize($element) . ' ' . ($element['#value']['upscale'] ? '(' . t('upscaling allowed') . ')' : ''); } function imagecache_scale_image(&$image, $data) { @@ -90,8 +125,8 @@ function imagecache_deprecated_scale_form($data) { function theme_imagecache_deprecated_scale($element) { $data = $element['#value']; - $options = array('inside' => t('Inside dimensions'), 'outside' => t('Outside dimensions')); - return 'width: '. $data['width'] .', height: '. $data['height'] .', fit: '. $options[$data['fit']]; + $fits = array('inside' => t('Inside dimensions'), 'outside' => t('Outside dimensions')); + return t('width: @width, height: @height, fit: @fit', array('@width' => $data['width'], '@height' => $data['height'], '@fit' => $fits[$data['fit']])); } function imagecache_deprecated_scale_image(&$image, $data) { @@ -146,7 +181,12 @@ function imagecache_crop_form($data) { function theme_imagecache_crop($element) { $data = $element['#value']; - return 'width: '. $data['width'] .', height: '. $data['height'] .', xoffset: '. $data['xoffset'] .', yoffset: '. $data['yoffset']; + return t('width: @width, height: @height, xoffset: @xoffset, yoffset: @yoffset', array( + '@width' => $data['width'], + '@height' => $data['height'], + '@xoffset' => $data['xoffset'], + '@yoffset' => $data['yoffset'], + )); } function imagecache_crop_image(&$image, $data) { @@ -206,10 +246,11 @@ function imagecache_rotate_form($data) { } function theme_imagecache_rotate($element) { - $output = t('degrees:') .' '. $element['#value']['degrees'] .', '; - $output .= t('randomize:') .' '. (($element['#value']['random']) ? t('Yes') : t('No')) .', '; - $output .= t('background:') .' '. strlen(trim($element['#value']['bgcolor'])) ? $element['#value']['bgcolor'] : t('Transparent/white'); - return $output; + $data = $element['#value']; + if ($data['random']) { + return t('random between -@degrees° and @degrees°', array('@degrees' => $data['degrees'])); + } + return t('@degrees°', array('@degrees' => $data['degrees'])); } function imagecache_rotate_image(&$image, $data) { @@ -274,11 +315,13 @@ function imagecache_sharpen_form($data) { } function theme_imagecache_sharpen($element) { - $output = t('radius: ') . $element['#value']['radius'] .', '; - $output .= t('sigma: ') . $element['#value']['sigma'] .', '; - $output .= t('amount: ') . $element['#value']['amount'] .', '; - $output .= t('threshold: ') . $element['#value']['threshold'] ; - return $output; + $data = $element['#value']; + return t('radius: @radius, sigma: @sigma, amount: @amount, threshold: @threshold', array( + '@radius' => $data['radius'], + '@sigma' => $data['sigma'], + '@amount' => $data['amount'], + '@threshold' => $data['threshold'], + )); } function imagecache_sharpen_image(&$image, $data) { -- 1.7.4.1