0a41e936718221c2d195e166132bb4087ce6eaf4
4 function imagecache_resize_form($action) {
5 $form['width'] = array(
6 '#type' => 'textfield',
7 '#title' => t('Width'),
8 '#default_value' => isset($action['width']) ?
$action['width'] : '100%',
9 '#description' => t('Enter a width in pixels or as a percentage. i.e. 500 or 80%.'),
11 $form['height'] = array(
12 '#type' => 'textfield',
13 '#title' => t('Height'),
14 '#default_value' => isset($action['height']) ?
$action['height'] : '100%',
15 '#description' => t('Enter a height in pixels or as a percentage. i.e. 500 or 80%.'),
20 function imagecache_resize_image(&$image, $data) {
21 if (!imageapi_image_resize($image, $data['width'], $data['height'])) {
22 watchdog('imagecache', 'imagecache_resize_image failed. image: %image, data: %data.', array('%path' => $image, '%data' => print_r($data, TRUE
)), WATCHDOG_ERROR
);
28 function theme_imagecache_resize($element) {
29 $data = $element['#value'];
30 return 'width: '.
$data['width'] .
', height: '.
$data['height'];
36 function imagecache_scale_form($data = array()) {
37 $form = imagecache_resize_form($data);
38 $form['upscale'] = array(
39 '#type' => 'checkbox',
40 '#default_value' => (isset($data['upscale'])) ?
$data['upscale'] : 0,
41 '#title' => t('Allow Upscaling'),
42 '#description' => t('Let scale make images larger than their original size'),
47 function theme_imagecache_scale($element) {
48 $output = theme_imagecache_resize($element) .
', upscale: ';
49 $output .
= ($element['#value']['upscale']) ?
t('Yes') : t('No');
53 function imagecache_scale_image(&$image, $data) {
54 // Set impossibly large values if the width and height aren't set.
55 $data['width'] = $data['width'] ?
$data['width'] : 9999999;
56 $data['height'] = $data['height'] ?
$data['height'] : 9999999;
57 if (!imageapi_image_scale($image, $data['width'], $data['height'], $data['upscale'])) {
58 watchdog('imagecache', 'imagecache_scale_image failed. image: %image, data: %data.', array('%image' => $image->source
, '%data' => print_r($data, TRUE
)), WATCHDOG_ERROR
);
66 * ImageCache Scale and Crop
68 function imagecache_scale_and_crop_form($data = array()) {
69 return imagecache_resize_form($data);
72 function theme_imagecache_scale_and_crop($element) {
73 return theme_imagecache_resize($element);
77 function imagecache_scale_and_crop_image(&$image, $data) {
78 if (!imageapi_image_scale_and_crop($image, $data['width'], $data['height'])) {
79 watchdog('imagecache', 'imagecache_scale_and_crop failed. image: %image, data: %data.', array('%image' => $image->source
, '%data' => print_r($data, TRUE
)), WATCHDOG_ERROR
);
88 * ImageCache Deprecated Scale.
89 * This will be removed in imagecache 2.1
91 function imagecache_deprecated_scale_form($data = array()) {
93 $helptext['inside'] = t('<strong>Inside dimensions</strong>: Final dimensions will be less than or equal to the entered width and height. Useful for ensuring a maximum height and/or width.');
94 $helptext['outside'] = t('<strong>Outside dimensions</strong>: Final dimensions will be greater than or equal to the entered width and height. Ideal for cropping the result to a square.');
95 $description = '<ul><li>'.
implode('</li><li>', $helptext) .
'</li><ul>';
99 '#title' => t('Scale to fit'),
100 '#options' => array('inside' => t('Inside dimensions'), 'outside' => t('Outside dimensions')),
101 '#default_value' => isset($data['fit']) ?
$data['fit'] : NULL
,
103 '#description' => $description,
105 $form['width'] = array(
106 '#type' => 'textfield',
107 '#title' => t('Width'),
108 '#default_value' => isset($data['width']) ?
$data['width'] : '',
109 '#description' => t('Enter a width in pixels or as a percentage. i.e. 500 or 80%.'),
111 $form['height'] = array(
112 '#type' => 'textfield',
113 '#title' => t('Height'),
114 '#default_value' => isset($data['height']) ?
$data['height'] : '',
115 '#description' => t('Enter a height in pixels or as a percentage. i.e. 500 or 80%.'),
120 function theme_imagecache_deprecated_scale($element) {
121 $data = $element['#value'];
122 $options = array('inside' => t('Inside dimensions'), 'outside' => t('Outside dimensions'));
123 return 'width: '.
$data['width'] .
', height: '.
$data['height'] .
', fit: '.
$options[$data['fit']];
126 function imagecache_deprecated_scale_image(&$image, $data) {
127 if ($data['fit'] == 'outside' && $data['width'] && $data['height']) {
128 $ratio = $image->info
['width'] / $image->info
['height'];
129 $new_ratio = $data['width']/$data['height'];
130 $data['width'] = $ratio > $new_ratio ?
0 : $data['width'];
131 $data['height'] = $ratio < $new_ratio ?
0 : $data['height'];
133 // Set impossibly large values if the width and height aren't set.
134 $data['width'] = $data['width'] ?
$data['width'] : 9999999;
135 $data['height'] = $data['height'] ?
$data['height'] : 9999999;
136 if (!imageapi_image_scale($image, $data['width'], $data['height'])) {
137 watchdog('imagecache', 'imagecache_deprecated_scale failed. image: %image, data: %data.', array('%image' => $image->source
, '%data' => print_r($data, TRUE
)), WATCHDOG_ERROR
);
148 function imagecache_crop_form($data = array()) {
155 $form['width'] = array(
156 '#type' => 'textfield',
157 '#title' => t('Width'),
158 '#default_value' => $data['width'],
159 '#description' => t('Enter a width in pixels or as a percentage. i.e. 500 or 80%.'),
161 $form['height'] = array(
162 '#type' => 'textfield',
163 '#title' => t('Height'),
164 '#default_value' => $data['height'],
165 '#description' => t('Enter a height in pixels or as a percentage. i.e. 500 or 80%.'),
167 $form['xoffset'] = array(
168 '#type' => 'textfield',
169 '#title' => t('X offset'),
170 '#default_value' => $data['xoffset'],
171 '#description' => t('Enter an offset in pixels or use a keyword: <em>left</em>, <em>center</em>, or <em>right</em>.'),
173 $form['yoffset'] = array(
174 '#type' => 'textfield',
175 '#title' => t('Y offset'),
176 '#default_value' => $data['yoffset'],
177 '#description' => t('Enter an offset in pixels or use a keyword: <em>top</em>, <em>center</em>, or <em>bottom</em>.'),
182 function theme_imagecache_crop($element) {
183 $data = $element['#value'];
184 return 'width: '.
$data['width'] .
', height: '.
$data['height'] .
', xoffset: '.
$data['xoffset'] .
', yoffset: '.
$data['yoffset'];
187 function imagecache_crop_image(&$image, $data) {
188 if (!imageapi_image_crop($image, $data['xoffset'], $data['yoffset'], $data['width'], $data['height'])) {
189 watchdog('imagecache', 'imagecache_crop failed. image: %image, data: %data.', array('%image' => $image->source
, '%data' => print_r($data, TRUE
)), WATCHDOG_ERROR
);
197 * ImageCache Desaturate
199 function imagecache_desaturate_form($data = array()) {
203 function theme_imagecache_desaturate($element) {
208 function imagecache_desaturate_image(&$image, $data = array()) {
209 if (!imageapi_image_desaturate($image)) {
210 watchdog('imagecache', 'imagecache_desaturate failed. image: %image, data: %data.', array('%image' => $image->source
, '%data' => print_r($data, TRUE
)), WATCHDOG_ERROR
);
221 function imagecache_rotate_form($data = array()) {
222 $form['degrees'] = array(
223 '#type' => 'textfield',
224 '#default_value' => (isset($data['degrees'])) ?
$data['degrees'] : 0,
225 '#title' => t('Rotation angle'),
226 '#description' => t('The number of degrees the image should be rotated. Positive numbers are clockwise, negative are counter-clockwise.'),
228 $form['random'] = array(
229 '#type' => 'checkbox',
230 '#default_value' => (isset($data['random'])) ?
$data['random'] : 0,
231 '#title' => t('Randomize'),
232 '#description' => t('Randomize the rotation angle for each image. The angle specified above is used as a maximum.'),
234 $form['bgcolor'] = array(
235 '#type' => 'textfield',
236 '#default_value' => (isset($data['bgcolor'])) ?
$data['bgcolor'] : '',
237 '#title' => t('Background color'),
238 '#description' => t('The background color to use for exposed areas of the image. Use web-style hex colors (#FFFFFF for white, #000000 for black). An empty value will cause images that support transparency to have transparent backgrounds, otherwise it will be white.'),
243 function theme_imagecache_rotate($element) {
244 $output = t('degrees:') .
' '.
$element['#value']['degrees'] .
', ';
245 $output .
= t('randomize:') .
' '.
(($element['#value']['random']) ?
t('Yes') : t('No')) .
', ';
246 $output .
= t('background:') .
' '.
strlen(trim($element['#value']['bgcolor'])) ?
$element['#value']['bgcolor'] : t('Transparent/white');
250 function imagecache_rotate_image(&$image, $data) {
251 // Merge in default values.
258 // Set sane default values.
259 if (strlen(trim($data['bgcolor']))) {
260 $data['bgcolor'] = hexdec(str_replace('#', '', $data['bgcolor']));
263 $data['bgcolor'] = NULL
;
266 if ($data['random']) {
267 $degrees = abs((float)$data['degrees']);
268 $data['degrees'] = rand(-1 * $degrees, $degrees);
271 if (!imageapi_image_rotate($image, $data['degrees'], $data['bgcolor'])) {
272 watchdog('imagecache', 'imagecache_rotate_image failed. image: %image, data: %data.', array('%image' => $image->source
, '%data' => print_r($data, TRUE
)), WATCHDOG_ERROR
);
281 function imagecache_sharpen_form($data) {
282 $form['info'] = array(
283 '#value' => t('<strong>NOTE:</strong> The sigma parameter below is currently <em>only</em> used when the Imagemagick toolkit is active.'),
285 $form['radius'] = array(
286 '#type' => 'textfield',
287 '#default_value' => (isset($data['radius'])) ?
$data['radius'] : '0.5' ,
288 '#title' => t('Radius'),
289 '#description' => t('The radius of the gaussian, in pixels, not counting the center pixel. If you\'re using Imagemagick, you can set this to 0 to let Imagemagick select a suitable radius. Typically 0.5 to 1 for screen resolutions. (default 0.5)'),
291 $form['sigma'] = array(
292 '#type' => 'textfield',
293 '#default_value' => (isset($data['sigma'])) ?
$data['sigma'] : '0.5' ,
294 '#title' => t('Sigma'),
295 '#description' => t('The standard deviation of the gaussian, in pixels. General rule of thumb: if radius < 1 then sigma = radius, else sigma = sqrt(radius). (default 0.5)'),
297 $form['amount'] = array(
298 '#type' => 'textfield',
299 '#default_value' => (isset($data['amount'])) ?
$data['amount'] : '100' ,
300 '#title' => t('Amount'),
301 '#description' => t('The percentage of the difference between the original and the blur image that is added back into the original. Typically 50 to 200. (default 100).'),
303 $form['threshold'] = array(
304 '#type' => 'textfield',
305 '#default_value' => (isset($data['threshold'])) ?
$data['threshold'] : '0.05' ,
306 '#title' => t('Threshold'),
307 '#description' => t('The threshold, as a fraction of max RGB levels, needed to apply the difference amount. Typically 0 to 0.2. (default 0.05).'),
312 function theme_imagecache_sharpen($element) {
313 $output = t('radius:') .
' '.
$element['#value']['radius'] .
', ';
314 $output .
= t('sigma:') .
' '.
$element['#value']['sigma'] .
', ';
315 $output .
= t('amount:') .
' '.
$element['#value']['amount'] .
', ';
316 $output .
= t('threshold:') .
' '.
$element['#value']['threshold'] ;
320 function imagecache_sharpen_image(&$image, $data) {
321 // Set sane default values.
322 $data['radius'] = $data['radius'] ?
$data['radius'] : "0.5";
323 $data['sigma'] = $data['sigma'] ?
$data['sigma'] : "0.5";
324 $data['amount'] = $data['amount'] ?
$data['amount'] : "100";
325 $data['threshold'] = $data['threshold'] ?
$data['threshold'] : "0.05";
327 if (!imageapi_image_sharpen($image, $data['radius'], $data['sigma'], $data['amount'], $data['threshold'])) {
328 watchdog('imagecache', 'imagecache_sharpen_image failed. image: %image, data: %data.', array('%image' => $image->source
, '%data' => print_r($data, TRUE
)), WATCHDOG_ERROR
);