| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
function image_help($path, $arg) {
|
| 13 |
|
| 14 |
case 'admin/help#image':
|
| 15 |
$naming_approaches = array();
|
| 16 |
$naming_approaches[] = t('Based on where it will be used: !name', array('!name' => '<code>profile-picture</code>'));
|
| 17 |
$naming_approaches[] = t('Describing its appearance: !name', array('!name' => '<code>square-85x85</code>'));
|
| 18 |
$output = '';
|
| 19 |
$output .= '<p>' . t('The Image module provides functionality for displaying images on your site though <a href="!url">image styles</a>.', array('!url' => url('admin/settings/image-styles'))) .'</p>';
|
| 20 |
$output .= '<h3>' . t('Image styles') . '</h3>';
|
| 21 |
$output .= '<p>' . t('Image <em>styles</em> allow your site to output an image in several different ways without affecting the original image. Any created images will automatically be refreshed if any changes are made to the image style.') .'</p>';
|
| 22 |
$output .= '<p>' . t('Every image style must have a name, which will be used in the URL of generated images. There are two common approaches to naming image styles:') . '</p>';
|
| 23 |
$output .= theme('item_list', $naming_approaches);
|
| 24 |
$output .= '<p>' . t('Both approaches are common and which you choose depends on how you use the image style.') . '</p>';
|
| 25 |
$output .= '<p>' . t('After creating an image style, <em>effects</em> may be added to the style. Image module comes with some basic effects such as <em>crop</em>, <em>scale</em>, <em>desaturate</em>, and <em>rotate</em>. In addition to the effects included with Image, other modules may provide additional effects. Multiple effects may be combined together, such as using the <em>crop and scale</em> effect and the <em>desaturate</em> effect, you could create square, grayscale thumbnails.');
|
| 26 |
return $output;
|
| 27 |
case 'admin/settings/image-styles':
|
| 28 |
return '<p>' . t('Image styles commonly provide thumbnail sizes by scaling and cropping images, but can also add various effects before an image is displayed. When an image is displayed with a style, a new file is created and the original image is left unchanged.') . '</p>';
|
| 29 |
case 'admin/settings/image-styles/edit/%/add/%':
|
| 30 |
case 'admin/settings/image-styles/edit/%/effects/%':
|
| 31 |
$effect = ($arg[5] == 'add') ? image_effect_definition_load($arg[6]) : image_effect_load($arg[6]);
|
| 32 |
return isset($effect['help']) ? ('<p>' . $effect['help'] . '</p>') : NULL;
|
| 33 |
}
|
| 34 |
}
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
function image_menu() {
|
| 40 |
$items = array();
|
| 41 |
|
| 42 |
$items['image/generate/%image_style'] = array(
|
| 43 |
'title' => 'Generate image style',
|
| 44 |
'page callback' => 'image_style_generate',
|
| 45 |
'page arguments' => array(2),
|
| 46 |
'access callback' => TRUE,
|
| 47 |
'type' => MENU_CALLBACK,
|
| 48 |
|
| 49 |
$items['admin/settings/image-styles'] = array(
|
| 50 |
'title' => 'Image styles',
|
| 51 |
'description' => 'Configure styles that can be used for resizing or adjusting images on display.',
|
| 52 |
'page callback' => 'image_style_list',
|
| 53 |
'access arguments' => array('administer image styles'),
|
| 54 |
|
| 55 |
$items['admin/settings/image-styles/list'] = array(
|
| 56 |
'title' => 'List',
|
| 57 |
'description' => 'List the current image styles on the site.',
|
| 58 |
'page callback' => 'image_style_list',
|
| 59 |
'access arguments' => array('administer image styles'),
|
| 60 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 61 |
'weight' => 1,
|
| 62 |
|
| 63 |
$items['admin/settings/image-styles/add'] = array(
|
| 64 |
'title' => 'Add style',
|
| 65 |
'description' => 'Add a new image style.',
|
| 66 |
'page callback' => 'drupal_get_form',
|
| 67 |
'page arguments' => array('image_style_add_form'),
|
| 68 |
'access arguments' => array('administer image styles'),
|
| 69 |
'type' => MENU_LOCAL_TASK,
|
| 70 |
'weight' => 2,
|
| 71 |
|
| 72 |
$items['admin/settings/image-styles/edit/%image_style'] = array(
|
| 73 |
'title' => 'Edit style',
|
| 74 |
'title callback' => 'image_style_title',
|
| 75 |
'title arguments' => array('!name', 4),
|
| 76 |
'description' => 'Configure an image style.',
|
| 77 |
'page callback' => 'drupal_get_form',
|
| 78 |
'page arguments' => array('image_style_form', 4),
|
| 79 |
'access arguments' => array('administer image styles'),
|
| 80 |
'type' => MENU_CALLBACK,
|
| 81 |
|
| 82 |
$items['admin/settings/image-styles/delete/%image_style'] = array(
|
| 83 |
'title' => 'Delete style',
|
| 84 |
'title callback' => 'image_style_title',
|
| 85 |
'title arguments' => array('Delete !name', 4),
|
| 86 |
'description' => 'Delete an image style.',
|
| 87 |
'page callback' => 'drupal_get_form',
|
| 88 |
'page arguments' => array('image_style_delete_form', 4, TRUE),
|
| 89 |
'access arguments' => array('administer image styles'),
|
| 90 |
'type' => MENU_CALLBACK,
|
| 91 |
|
| 92 |
$items['admin/settings/image-styles/edit/%image_style/effects/%image_effect'] = array(
|
| 93 |
'title' => 'Edit image effect',
|
| 94 |
'title callback' => 'image_effect_title',
|
| 95 |
'title arguments' => array('!label effect', 6),
|
| 96 |
'description' => 'Edit an exiting effect within a style.',
|
| 97 |
'page callback' => 'drupal_get_form',
|
| 98 |
'page arguments' => array('image_effect_form', 4, 6),
|
| 99 |
'access arguments' => array('administer image styles'),
|
| 100 |
'type' => MENU_CALLBACK,
|
| 101 |
|
| 102 |
$items['admin/settings/image-styles/edit/%image_style/effects/%image_effect/delete'] = array(
|
| 103 |
'title' => 'Delete image effect',
|
| 104 |
'title callback' => 'image_effect_title',
|
| 105 |
'title arguments' => array('Delete !label', 6),
|
| 106 |
'description' => 'Delete an exiting effect from a style.',
|
| 107 |
'page callback' => 'drupal_get_form',
|
| 108 |
'page arguments' => array('image_effect_delete_form', 4, 6),
|
| 109 |
'access arguments' => array('administer image styles'),
|
| 110 |
'type' => MENU_CALLBACK,
|
| 111 |
|
| 112 |
$items['admin/settings/image-styles/edit/%image_style/add/%image_effect_definition'] = array(
|
| 113 |
'title' => 'Add image effect',
|
| 114 |
'title callback' => 'image_effect_title',
|
| 115 |
'title arguments' => array('Add !label effect', 6),
|
| 116 |
'description' => 'Add a new effect to a style.',
|
| 117 |
'page callback' => 'drupal_get_form',
|
| 118 |
'page arguments' => array('image_effect_form', 4, 6),
|
| 119 |
'access arguments' => array('administer image styles'),
|
| 120 |
'type' => MENU_CALLBACK,
|
| 121 |
|
| 122 |
|
| 123 |
return $items;
|
| 124 |
}
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
function image_theme() {
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
'style' => NULL,
|
| 134 |
'path' => NULL,
|
| 135 |
'alt' => '',
|
| 136 |
'title' => '',
|
| 137 |
'attributes' => array(),
|
| 138 |
'getsize' => TRUE,
|
| 139 |
),
|
| 140 |
),
|
| 141 |
|
| 142 |
'arguments' => array('styles' => NULL),
|
| 143 |
),
|
| 144 |
|
| 145 |
'arguments' => array('form' => NULL),
|
| 146 |
),
|
| 147 |
|
| 148 |
'arguments' => array('style' => NULL),
|
| 149 |
),
|
| 150 |
|
| 151 |
'arguments' => array('element' => NULL),
|
| 152 |
),
|
| 153 |
|
| 154 |
'arguments' => array('data' => NULL),
|
| 155 |
),
|
| 156 |
|
| 157 |
'arguments' => array('data' => NULL),
|
| 158 |
),
|
| 159 |
|
| 160 |
'arguments' => array('data' => NULL),
|
| 161 |
),
|
| 162 |
|
| 163 |
'arguments' => array('data' => NULL),
|
| 164 |
),
|
| 165 |
);
|
| 166 |
}
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
function image_permission() {
|
| 172 |
|
| 173 |
|
| 174 |
'title' => t('Administer image styles'),
|
| 175 |
'description' => t('Create and modify styles for generating image modifications such as thumbnails.'),
|
| 176 |
),
|
| 177 |
);
|
| 178 |
}
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
function image_flush_caches() {
|
| 184 |
return array('cache_image');
|
| 185 |
}
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
function image_file_download($filepath) {
|
| 193 |
if (strpos($filepath, 'styles/') === 0) {
|
| 194 |
$args = explode('/', $filepath);
|
| 195 |
|
| 196 |
array_shift($args);
|
| 197 |
|
| 198 |
$style_name = array_shift($args);
|
| 199 |
|
| 200 |
$original_path = implode('/', $args);
|
| 201 |
|
| 202 |
|
| 203 |
if ($info = image_get_info(file_create_path($filepath))) {
|
| 204 |
|
| 205 |
$headers = module_invoke_all('file_download', $original_path);
|
| 206 |
if (!in_array(-1, $headers)) {
|
| 207 |
|
| 208 |
'Content-Type' => $info['mime_type'],
|
| 209 |
'Content-Length' => $info['file_size'],
|
| 210 |
);
|
| 211 |
}
|
| 212 |
}
|
| 213 |
return -1;
|
| 214 |
}
|
| 215 |
}
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
function image_file_move($file, $source) {
|
| 221 |
|
| 222 |
image_path_flush($file->filepath);
|
| 223 |
}
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
function image_file_delete($file) {
|
| 229 |
|
| 230 |
image_path_flush($file->filepath);
|
| 231 |
}
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
function image_path_flush($path) {
|
| 240 |
$path = file_directory_strip($path);
|
| 241 |
$styles = image_styles();
|
| 242 |
foreach ($styles as $style) {
|
| 243 |
if ($path = file_create_path('styles/' . $style['name'] . '/' . $path)) {
|
| 244 |
file_unmanaged_delete($path);
|
| 245 |
}
|
| 246 |
}
|
| 247 |
}
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
function image_styles() {
|
| 257 |
$styles = &drupal_static(__FUNCTION__);
|
| 258 |
|
| 259 |
|
| 260 |
if (!isset($styles)) {
|
| 261 |
if ($cache = cache_get('image_styles', 'cache')) {
|
| 262 |
$styles = $cache->data;
|
| 263 |
}
|
| 264 |
|
| 265 |
$styles = array();
|
| 266 |
$result = db_select('image_styles', NULL, array('fetch' => PDO::FETCH_ASSOC))
|
| 267 |
->fields('image_styles')
|
| 268 |
->orderBy('name')
|
| 269 |
->execute();
|
| 270 |
foreach ($result as $style) {
|
| 271 |
$styles[$style['name']] = $style;
|
| 272 |
$styles[$style['name']]['effects'] = image_style_effects($style);
|
| 273 |
}
|
| 274 |
|
| 275 |
cache_set('image_styles', $styles);
|
| 276 |
|
| 277 |
}
|
| 278 |
|
| 279 |
return $styles;
|
| 280 |
}
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
function image_style_load($name = NULL, $isid = NULL) {
|
| 298 |
$styles = image_styles();
|
| 299 |
|
| 300 |
|
| 301 |
if (isset($name) && isset($styles[$name])) {
|
| 302 |
return $styles[$name];
|
| 303 |
}
|
| 304 |
|
| 305 |
|
| 306 |
if (isset($isid)) {
|
| 307 |
foreach ($styles as $name => $style) {
|
| 308 |
if ($style['isid'] == $isid) {
|
| 309 |
return $style;
|
| 310 |
}
|
| 311 |
}
|
| 312 |
}
|
| 313 |
|
| 314 |
|
| 315 |
return FALSE;
|
| 316 |
}
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
function image_style_save($style) {
|
| 327 |
if (isset($style['isid']) && is_numeric($style['isid'])) {
|
| 328 |
|
| 329 |
$old_style = image_style_load(NULL, $style['isid']);
|
| 330 |
image_style_flush($old_style);
|
| 331 |
drupal_write_record('image_styles', $style, 'isid');
|
| 332 |
if ($old_style['name'] != $style['name']) {
|
| 333 |
$style['old_name'] = $old_style['name'];
|
| 334 |
}
|
| 335 |
}
|
| 336 |
|
| 337 |
drupal_write_record('image_styles', $style);
|
| 338 |
$style['is_new'] = TRUE;
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
module_invoke_all('image_style_save', $style);
|
| 343 |
|
| 344 |
|
| 345 |
image_style_flush($style);
|
| 346 |
|
| 347 |
return $style;
|
| 348 |
}
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
function image_style_delete($style, $replacement_style_name = '') {
|
| 362 |
image_style_flush($style);
|
| 363 |
|
| 364 |
db_delete('image_effects')->condition('isid', $style['isid'])->execute();
|
| 365 |
db_delete('image_styles')->condition('isid', $style['isid'])->execute();
|
| 366 |
|
| 367 |
|
| 368 |
$style['old_name'] = $style['name'];
|
| 369 |
$style['name'] = $replacement_style_name;
|
| 370 |
module_invoke_all('image_style_delete', $style);
|
| 371 |
|
| 372 |
return TRUE;
|
| 373 |
}
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
function image_style_effects($style) {
|
| 386 |
$effects = image_effects();
|
| 387 |
$style_effects = array();
|
| 388 |
foreach ($effects as $effect) {
|
| 389 |
if ($style['isid'] == $effect['isid']) {
|
| 390 |
$style_effects[$effect['ieid']] = $effect;
|
| 391 |
}
|
| 392 |
}
|
| 393 |
|
| 394 |
return $style_effects;
|
| 395 |
}
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
function image_style_options($include_empty = TRUE) {
|
| 406 |
$styles = image_styles();
|
| 407 |
$options = array();
|
| 408 |
if ($include_empty && !empty($styles)) {
|
| 409 |
$options[''] = t('<none>');
|
| 410 |
}
|
| 411 |
$options = array_merge($options, drupal_map_assoc(array_keys($styles)));
|
| 412 |
if (empty($options)) {
|
| 413 |
$options[''] = t('No defined styles');
|
| 414 |
}
|
| 415 |
return $options;
|
| 416 |
}
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
function image_style_generate() {
|
| 426 |
$args = func_get_args();
|
| 427 |
$style = array_shift($args);
|
| 428 |
$style_name = $style['name'];
|
| 429 |
$path = implode('/', $args);
|
| 430 |
|
| 431 |
$source = file_create_path($path);
|
| 432 |
$path_md5 = md5($path);
|
| 433 |
$destination = image_style_path($style['name'], $path);
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
if (!$style || !cache_get('access:' . $style_name . ':' . $path_md5, 'cache_image')) {
|
| 438 |
drupal_access_denied();
|
| 439 |
exit();
|
| 440 |
}
|
| 441 |
|
| 442 |
|
| 443 |
$cid = 'generate:' . $style_name . ':' . $path_md5;
|
| 444 |
if (cache_get($cid, 'cache_image')) {
|
| 445 |
|
| 446 |
|
| 447 |
drupal_set_header('503 Service Unavailable');
|
| 448 |
drupal_set_header('Retry-After', 3);
|
| 449 |
print t('Image generation in progress, please try again shortly.');
|
| 450 |
exit();
|
| 451 |
}
|
| 452 |
|
| 453 |
|
| 454 |
if ($image = image_load($destination)) {
|
| 455 |
file_transfer($image->source, array('Content-Type' => $image->info['mime_type'], 'Content-Length' => $image->info['file_size']));
|
| 456 |
}
|
| 457 |
|
| 458 |
|
| 459 |
cache_set($cid, $destination, 'cache_image');
|
| 460 |
|
| 461 |
|
| 462 |
if (image_style_create_derivative($style, $source, $destination)) {
|
| 463 |
$image = image_load($destination);
|
| 464 |
cache_clear_all($cid, 'cache_image');
|
| 465 |
file_transfer($image->source, array('Content-Type' => $image->info['mime_type'], 'Content-Length' => $image->info['file_size']));
|
| 466 |
}
|
| 467 |
|
| 468 |
cache_clear_all($cid, 'cache_image');
|
| 469 |
watchdog('image', 'Unable to generate the derived image located at %path.', $destination);
|
| 470 |
drupal_set_header('500 Internal Server Error');
|
| 471 |
print t('Error generating image.');
|
| 472 |
exit();
|
| 473 |
|
| 474 |
}
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
function image_style_create_derivative($style, $source, $destination) {
|
| 490 |
|
| 491 |
$directory = dirname($destination);
|
| 492 |
|
| 493 |
|
| 494 |
if (!file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
|
| 495 |
watchdog('image', 'Failed to create style directory: %directory', array('%directory' => $directory), WATCHDOG_ERROR);
|
| 496 |
return FALSE;
|
| 497 |
}
|
| 498 |
|
| 499 |
if (!$image = image_load($source)) {
|
| 500 |
return FALSE;
|
| 501 |
}
|
| 502 |
|
| 503 |
foreach ($style['effects'] as $effect) {
|
| 504 |
image_effect_apply($image, $effect);
|
| 505 |
}
|
| 506 |
|
| 507 |
if (!image_save($image, $destination)) {
|
| 508 |
if (file_exists($destination)) {
|
| 509 |
watchdog('image', 'Cached image file %destination already exists. There may be an issue with your rewrite configuration.', array('%destination' => $destination), WATCHDOG_ERROR);
|
| 510 |
}
|
| 511 |
return FALSE;
|
| 512 |
}
|
| 513 |
|
| 514 |
return TRUE;
|
| 515 |
}
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
function image_style_flush($style) {
|
| 524 |
$style_directory = realpath(file_directory_path() . '/styles/' . $style['name']);
|
| 525 |
if (is_dir($style_directory)) {
|
| 526 |
file_unmanaged_delete_recursive($style_directory);
|
| 527 |
}
|
| 528 |
|
| 529 |
|
| 530 |
module_invoke_all('image_style_flush', $style);
|
| 531 |
|
| 532 |
|
| 533 |
cache_clear_all('image_styles', 'cache');
|
| 534 |
cache_clear_all('image_effects', 'cache');
|
| 535 |
drupal_static_reset('image_styles');
|
| 536 |
drupal_static_reset('image_effects');
|
| 537 |
|
| 538 |
|
| 539 |
if (module_exists('block')) {
|
| 540 |
cache_clear_all('*', 'cache_block', TRUE);
|
| 541 |
}
|
| 542 |
cache_clear_all('*', 'cache_page', TRUE);
|
| 543 |
}
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
function image_style_url($style_name, $path) {
|
| 564 |
$destination = image_style_path($style_name, $path);
|
| 565 |
|
| 566 |
|
| 567 |
if (file_exists($destination)) {
|
| 568 |
return file_create_url($destination);
|
| 569 |
}
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
drupal_page_is_cacheable(FALSE);
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
cache_set('access:' . $style_name . ':' . md5($path), 1, 'cache_image', REQUEST_TIME + 600);
|
| 578 |
|
| 579 |
|
| 580 |
$url = url('image/generate/' . $style_name . '/' . $path, array('absolute' => TRUE));
|
| 581 |
return $url;
|
| 582 |
}
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
function image_style_path($style_name, $path) {
|
| 599 |
return file_directory_path() . '/styles/' . $style_name . '/' . file_directory_strip($path);
|
| 600 |
}
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
function image_effect_definitions() {
|
| 611 |
$effects = &drupal_static(__FUNCTION__);
|
| 612 |
|
| 613 |
if (!isset($effects)) {
|
| 614 |
if ($cache = cache_get('image_effects') && !empty($cache->data)) {
|
| 615 |
$effects = $cache->data;
|
| 616 |
}
|
| 617 |
|
| 618 |
$effects = array();
|
| 619 |
foreach (module_implements('image_effect_info') as $module) {
|
| 620 |
foreach (module_invoke($module, 'image_effect_info') as $name => $effect) {
|
| 621 |
|
| 622 |
$effect['module'] = $module;
|
| 623 |
$effect['name'] = $name;
|
| 624 |
$effect['data'] = isset($effect['data']) ? $effect['data'] : array();
|
| 625 |
$effects[$name] = $effect;
|
| 626 |
};
|
| 627 |
}
|
| 628 |
uasort($effects, '_image_effect_definitions_sort');
|
| 629 |
cache_set('image_effects', $effects);
|
| 630 |
|
| 631 |
}
|
| 632 |
|
| 633 |
return $effects;
|
| 634 |
}
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
function image_effect_definition_load($effect) {
|
| 659 |
$definitions = image_effect_definitions();
|
| 660 |
return isset($definitions[$effect]) ? $definitions[$effect] : FALSE;
|
| 661 |
}
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
function image_effects() {
|
| 671 |
$effects = &drupal_static(__FUNCTION__);
|
| 672 |
|
| 673 |
if (!isset($effects)) {
|
| 674 |
$effects = array();
|
| 675 |
|
| 676 |
|
| 677 |
$result = db_select('image_effects', NULL, array('fetch' => PDO::FETCH_ASSOC))
|
| 678 |
->fields('image_effects')
|
| 679 |
->orderBy('image_effects.weight', 'ASC')
|
| 680 |
->execute();
|
| 681 |
foreach ($result as $effect) {
|
| 682 |
$effect['data'] = unserialize($effect['data']);
|
| 683 |
$definition = image_effect_definition_load($effect['name']);
|
| 684 |
|
| 685 |
if ($definition) {
|
| 686 |
$effect = array_merge($definition, $effect);
|
| 687 |
$effects[$effect['ieid']] = $effect;
|
| 688 |
}
|
| 689 |
}
|
| 690 |
}
|
| 691 |
|
| 692 |
return $effects;
|
| 693 |
}
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
function image_effect_load($ieid) {
|
| 714 |
$effects = image_effects();
|
| 715 |
return isset($effects[$ieid]) ? $effects[$ieid] : FALSE;
|
| 716 |
}
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
function image_effect_save($effect) {
|
| 727 |
if (!empty($effect['ieid'])) {
|
| 728 |
drupal_write_record('image_effects', $effect, 'ieid');
|
| 729 |
}
|
| 730 |
|
| 731 |
drupal_write_record('image_effects', $effect);
|
| 732 |
|
| 733 |
$style = image_style_load(NULL, $effect['isid']);
|
| 734 |
image_style_flush($style);
|
| 735 |
return $effect;
|
| 736 |
}
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
function image_effect_delete($effect) {
|
| 745 |
db_delete('image_effects')->condition('ieid', $effect['ieid'])->execute();
|
| 746 |
$style = image_style_load(NULL, $effect['isid']);
|
| 747 |
image_style_flush($style);
|
| 748 |
}
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
function image_effect_apply($image, $effect) {
|
| 761 |
if (drupal_function_exists($effect['effect callback'])) {
|
| 762 |
return call_user_func($effect['effect callback'], $image, $effect['data']);
|
| 763 |
}
|
| 764 |
return FALSE;
|
| 765 |
}
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
function theme_image_style($style_name, $path, $alt = '', $title = '', $attributes = array(), $getsize = TRUE) {
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
$style_path = image_style_path($style_name, $path);
|
| 795 |
if (!file_exists($style_path)) {
|
| 796 |
$style_path = image_style_url($style_name, $path);
|
| 797 |
}
|
| 798 |
return theme('image', $style_path, $alt, $title, $attributes, $getsize);
|
| 799 |
}
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
function image_filter_percent($value, $current_pixels) {
|
| 805 |
if (strpos($value, '%') !== FALSE) {
|
| 806 |
$value = str_replace('%', '', $value) * 0.01 * $current_pixels;
|
| 807 |
}
|
| 808 |
return $value;
|
| 809 |
}
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
function image_filter_keyword($value, $current_pixels, $new_pixels) {
|
| 819 |
|
| 820 |
case 'top':
|
| 821 |
case 'left':
|
| 822 |
return 0;
|
| 823 |
|
| 824 |
case 'bottom':
|
| 825 |
case 'right':
|
| 826 |
return $current_pixels - $new_pixels;
|
| 827 |
|
| 828 |
case 'center':
|
| 829 |
return $current_pixels / 2 - $new_pixels / 2;
|
| 830 |
}
|
| 831 |
return $value;
|
| 832 |
}
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
function _image_effect_definitions_sort($a, $b) {
|
| 840 |
return strcasecmp($a['name'], $b['name']);
|
| 841 |
}
|
| 842 |
|