| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: imagecache_actions.inc,v 1.24.2.3 2009/08/19 21:05:31 drewish Exp $ 3 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%.'), 10 ); 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%.'), 16 ); 17 return $form; 18 } 19 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); 23 return FALSE; 24 } 25 return TRUE; 26 } 27 28 function theme_imagecache_resize($element) { 29 $data = $element['#value']; 30 if ($data['width'] && $data['height']) { 31 return check_plain($data['width']) . 'x' . check_plain($data['height']); 32 } 33 return ($data['width']) ? t('width @width', array('@width' => $data['width'])) : t('height @height', array('@height' => $data['height'])); 34 } 35 36 /** 37 * ImageCache Scale 38 */ 39 function imagecache_scale_form($data = array()) { 40 $form = imagecache_resize_form($data); 41 $form['upscale'] = array( 42 '#type' => 'checkbox', 43 '#default_value' => (isset($data['upscale'])) ? $data['upscale'] : 0, 44 '#title' => t('Allow Upscaling'), 45 '#description' => t('Let scale make images larger than their original size'), 46 ); 47 return $form; 48 } 49 50 function theme_imagecache_scale($element) { 51 return theme_imagecache_resize($element) . ' ' . ($element['#value']['upscale'] ? '(' . t('upscaling allowed') . ')' : ''); 52 } 53 54 function imagecache_scale_image(&$image, $data) { 55 // Set impossibly large values if the width and height aren't set. 56 $data['width'] = $data['width'] ? $data['width'] : 9999999; 57 $data['height'] = $data['height'] ? $data['height'] : 9999999; 58 if (!imageapi_image_scale($image, $data['width'], $data['height'], $data['upscale'])) { 59 watchdog('imagecache', 'imagecache_scale_image failed. image: %image, data: %data.', array('%image' => $image->source, '%data' => print_r($data, TRUE)), WATCHDOG_ERROR); 60 return FALSE; 61 } 62 return TRUE; 63 } 64 65 66 /** 67 * ImageCache Scale and Crop 68 */ 69 function imagecache_scale_and_crop_form($data = array()) { 70 return imagecache_resize_form($data); 71 } 72 73 function theme_imagecache_scale_and_crop($element) { 74 return theme_imagecache_resize($element); 75 } 76 77 78 function imagecache_scale_and_crop_image(&$image, $data) { 79 if (!imageapi_image_scale_and_crop($image, $data['width'], $data['height'])) { 80 watchdog('imagecache', 'imagecache_scale_and_crop failed. image: %image, data: %data.', array('%image' => $image->source, '%data' => print_r($data, TRUE)), WATCHDOG_ERROR); 81 return FALSE; 82 } 83 return TRUE; 84 } 85 86 87 88 /** 89 * ImageCache Deprecated Scale. 90 * This will be removed in imagecache 2.1 91 */ 92 function imagecache_deprecated_scale_form($data = array()) { 93 $helptext = array(); 94 $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.'); 95 $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.'); 96 $description = '<ul><li>'. implode('</li><li>', $helptext) .'</li><ul>'; 97 98 $form['fit'] = array( 99 '#type' => 'select', 100 '#title' => t('Scale to fit'), 101 '#options' => array('inside' => t('Inside dimensions'), 'outside' => t('Outside dimensions')), 102 '#default_value' => isset($data['fit']) ? $data['fit'] : NULL, 103 '#weight' => 1, 104 '#description' => $description, 105 ); 106 $form['width'] = array( 107 '#type' => 'textfield', 108 '#title' => t('Width'), 109 '#default_value' => isset($data['width']) ? $data['width'] : '', 110 '#description' => t('Enter a width in pixels or as a percentage. i.e. 500 or 80%.'), 111 ); 112 $form['height'] = array( 113 '#type' => 'textfield', 114 '#title' => t('Height'), 115 '#default_value' => isset($data['height']) ? $data['height'] : '', 116 '#description' => t('Enter a height in pixels or as a percentage. i.e. 500 or 80%.'), 117 ); 118 return $form; 119 } 120 121 function theme_imagecache_deprecated_scale($element) { 122 $data = $element['#value']; 123 $fits = array('inside' => t('Inside dimensions'), 'outside' => t('Outside dimensions')); 124 return t('width: @width, height: @height, fit: @fit', array('@width' => $data['width'], '@height' => $data['height'], '@fit' => $fits[$data['fit']])); 125 } 126 127 function imagecache_deprecated_scale_image(&$image, $data) { 128 if ($data['fit'] == 'outside' && $data['width'] && $data['height']) { 129 $ratio = $image->info['width'] / $image->info['height']; 130 $new_ratio = $data['width']/$data['height']; 131 $data['width'] = $ratio > $new_ratio ? 0 : $data['width']; 132 $data['height'] = $ratio < $new_ratio ? 0 : $data['height']; 133 } 134 // Set impossibly large values if the width and height aren't set. 135 $data['width'] = $data['width'] ? $data['width'] : 9999999; 136 $data['height'] = $data['height'] ? $data['height'] : 9999999; 137 if (!imageapi_image_scale($image, $data['width'], $data['height'])) { 138 watchdog('imagecache', 'imagecache_deprecated_scale failed. image: %image, data: %data.', array('%image' => $image->source, '%data' => print_r($data, TRUE)), WATCHDOG_ERROR); 139 return FALSE; 140 } 141 return TRUE; 142 } 143 144 145 146 /** 147 * ImageCache Crop 148 */ 149 function imagecache_crop_form($data = array()) { 150 $data += array( 151 'width' => '', 152 'height' => '', 153 'xoffset' => '', 154 'yoffset' => '', 155 ); 156 $form['width'] = array( 157 '#type' => 'textfield', 158 '#title' => t('Width'), 159 '#default_value' => $data['width'], 160 '#description' => t('Enter a width in pixels or as a percentage. i.e. 500 or 80%.'), 161 ); 162 $form['height'] = array( 163 '#type' => 'textfield', 164 '#title' => t('Height'), 165 '#default_value' => $data['height'], 166 '#description' => t('Enter a height in pixels or as a percentage. i.e. 500 or 80%.'), 167 ); 168 $form['xoffset'] = array( 169 '#type' => 'textfield', 170 '#title' => t('X offset'), 171 '#default_value' => $data['xoffset'], 172 '#description' => t('Enter an offset in pixels or use a keyword: <em>left</em>, <em>center</em>, or <em>right</em>.'), 173 ); 174 $form['yoffset'] = array( 175 '#type' => 'textfield', 176 '#title' => t('Y offset'), 177 '#default_value' => $data['yoffset'], 178 '#description' => t('Enter an offset in pixels or use a keyword: <em>top</em>, <em>center</em>, or <em>bottom</em>.'), 179 ); 180 return $form; 181 } 182 183 function theme_imagecache_crop($element) { 184 $data = $element['#value']; 185 return t('width: @width, height: @height, xoffset: @xoffset, yoffset: @yoffset', array( 186 '@width' => $data['width'], 187 '@height' => $data['height'], 188 '@xoffset' => $data['xoffset'], 189 '@yoffset' => $data['yoffset'], 190 )); 191 } 192 193 function imagecache_crop_image(&$image, $data) { 194 if (!imageapi_image_crop($image, $data['xoffset'], $data['yoffset'], $data['width'], $data['height'])) { 195 watchdog('imagecache', 'imagecache_crop failed. image: %image, data: %data.', array('%image' => $image->source, '%data' => print_r($data, TRUE)), WATCHDOG_ERROR); 196 return FALSE; 197 } 198 return TRUE; 199 } 200 201 202 /** 203 * ImageCache Desaturate 204 */ 205 function imagecache_desaturate_form($data = array()) { 206 return array(); 207 } 208 209 function theme_imagecache_desaturate($element) { 210 return ''; 211 } 212 213 214 function imagecache_desaturate_image(&$image, $data = array()) { 215 if (!imageapi_image_desaturate($image)) { 216 watchdog('imagecache', 'imagecache_desaturate failed. image: %image, data: %data.', array('%image' => $image->source, '%data' => print_r($data, TRUE)), WATCHDOG_ERROR); 217 return FALSE; 218 } 219 return TRUE; 220 } 221 222 223 224 /** 225 * ImageCache Rotate 226 */ 227 function imagecache_rotate_form($data = array()) { 228 $form['degrees'] = array( 229 '#type' => 'textfield', 230 '#default_value' => (isset($data['degrees'])) ? $data['degrees'] : 0, 231 '#title' => t('Rotation angle'), 232 '#description' => t('The number of degrees the image should be rotated. Positive numbers are clockwise, negative are counter-clockwise.'), 233 ); 234 $form['random'] = array( 235 '#type' => 'checkbox', 236 '#default_value' => (isset($data['random'])) ? $data['random'] : 0, 237 '#title' => t('Randomize'), 238 '#description' => t('Randomize the rotation angle for each image. The angle specified above is used as a maximum.'), 239 ); 240 $form['bgcolor'] = array( 241 '#type' => 'textfield', 242 '#default_value' => (isset($data['bgcolor'])) ? $data['bgcolor'] : '', 243 '#title' => t('Background color'), 244 '#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.'), 245 ); 246 return $form; 247 } 248 249 function theme_imagecache_rotate($element) { 250 $data = $element['#value']; 251 if ($data['random']) { 252 return t('random between -@degrees° and @degrees°', array('@degrees' => $data['degrees'])); 253 } 254 return t('@degrees°', array('@degrees' => $data['degrees'])); 255 } 256 257 function imagecache_rotate_image(&$image, $data) { 258 // Merge in default values. 259 $data += array( 260 'degrees' => '0', 261 'random' => FALSE, 262 'bgcolor' => '', 263 ); 264 265 // Set sane default values. 266 if (strlen(trim($data['bgcolor']))) { 267 $data['bgcolor'] = hexdec(str_replace('#', '', $data['bgcolor'])); 268 } 269 else { 270 $data['bgcolor'] = NULL; 271 } 272 273 if ($data['random']) { 274 $degrees = abs((float)$data['degrees']); 275 $data['degrees'] = rand(-1 * $degrees, $degrees); 276 } 277 278 if (!imageapi_image_rotate($image, $data['degrees'], $data['bgcolor'])) { 279 watchdog('imagecache', 'imagecache_rotate_image failed. image: %image, data: %data.', array('%image' => $image->source, '%data' => print_r($data, TRUE)), WATCHDOG_ERROR); 280 return FALSE; 281 } 282 return TRUE; 283 } 284 285 /** 286 * ImageCache Sharpen 287 */ 288 function imagecache_sharpen_form($data) { 289 $form['info'] = array( 290 '#value' => t('<strong>NOTE:</strong> The sigma parameter below is currently <em>only</em> used when the Imagemagick toolkit is active.'), 291 ); 292 $form['radius'] = array( 293 '#type' => 'textfield', 294 '#default_value' => (isset($data['radius'])) ? $data['radius'] : '0.5' , 295 '#title' => t('Radius'), 296 '#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)'), 297 ); 298 $form['sigma'] = array( 299 '#type' => 'textfield', 300 '#default_value' => (isset($data['sigma'])) ? $data['sigma'] : '0.5' , 301 '#title' => t('Sigma'), 302 '#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)'), 303 ); 304 $form['amount'] = array( 305 '#type' => 'textfield', 306 '#default_value' => (isset($data['amount'])) ? $data['amount'] : '100' , 307 '#title' => t('Amount'), 308 '#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).'), 309 ); 310 $form['threshold'] = array( 311 '#type' => 'textfield', 312 '#default_value' => (isset($data['threshold'])) ? $data['threshold'] : '0.05' , 313 '#title' => t('Threshold'), 314 '#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).'), 315 ); 316 return $form; 317 } 318 319 function theme_imagecache_sharpen($element) { 320 $data = $element['#value']; 321 return t('radius: @radius, sigma: @sigma, amount: @amount, threshold: @threshold', array( 322 '@radius' => $data['radius'], 323 '@sigma' => $data['sigma'], 324 '@amount' => $data['amount'], 325 '@threshold' => $data['threshold'], 326 )); 327 } 328 329 function imagecache_sharpen_image(&$image, $data) { 330 // Set sane default values. 331 $data['radius'] = $data['radius'] ? $data['radius'] : "0.5"; 332 $data['sigma'] = $data['sigma'] ? $data['sigma'] : "0.5"; 333 $data['amount'] = $data['amount'] ? $data['amount'] : "100"; 334 $data['threshold'] = $data['threshold'] ? $data['threshold'] : "0.05"; 335 336 if (!imageapi_image_sharpen($image, $data['radius'], $data['sigma'], $data['amount'], $data['threshold'])) { 337 watchdog('imagecache', 'imagecache_sharpen_image failed. image: %image, data: %data.', array('%image' => $image->source, '%data' => print_r($data, TRUE)), WATCHDOG_ERROR); 338 return FALSE; 339 } 340 return TRUE; 341 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |