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