You are here

function collageformatter_image_effect_callback in Collage Formatter 7

Collage Formatter image effect.

1 string reference to 'collageformatter_image_effect_callback'
collageformatter_image_effect_info in ./collageformatter.module
Implements hook_image_effect_info().

File

./collageformatter.module, line 1037
Main file for Collage Formatter module.

Code

function collageformatter_image_effect_callback(&$image, $data) {
  if (strpos(drupal_basename($image->source), '_copy_') !== FALSE || strpos(drupal_basename($image->source), '_symlink_') !== FALSE || strpos(drupal_basename($image->source), '_fake_') !== FALSE) {
    $dimensions = preg_replace('/.+\\/([\\d]+x[\\d]+)_(copy|symlink|fake)_.+/', '$1', $image->source);
    list($image_width, $image_height) = explode('x', $dimensions);
    $original_image_uri = preg_replace('/(.+\\/)collageformatter\\/(.+\\/)[\\d]+x[\\d]+_(copy|symlink|fake)_(.+)/', '$1$2$4', $image->source);

    // If it is a fake image - we need to load the real image resource.
    if (strpos(drupal_basename($image->source), '_fake_') !== FALSE) {
      $original_image = image_load($original_image_uri);
      $image->info = $original_image->info;
      $image->resource = $original_image->resource;
    }
    $image->source = $original_image_uri;
    $effect_callback = 'image_scale_and_crop_effect';
    if (module_exists('focal_point')) {
      $effect_callback = 'focal_point_scale_and_crop_effect';
    }
    if (isset($image_width) && isset($image_height)) {
      return image_effect_apply($image, array(
        'effect callback' => $effect_callback,
        'data' => array(
          'width' => $image_width,
          'height' => $image_height,
        ),
      ));
    }
  }
  return FALSE;
}