You are here

function _collageformatter_image_file_check in Collage Formatter 7

Checks for/creates the original image reference file.

1 call to _collageformatter_image_file_check()
_collageformatter_render_box in ./collageformatter.module
Recursive function to render the box.

File

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

Code

function _collageformatter_image_file_check($box, $settings) {
  $image_width = round($box['total_width'] - 2 * $settings['border_size'] - $settings['gap_size'] - 0.5);
  $image_height = round($box['total_height'] - 2 * $settings['border_size'] - $settings['gap_size'] - 0.5);
  $filename = $image_width . 'x' . $image_height . '_' . $settings['advanced']['original_image_reference'] . '_' . drupal_basename($box['uri']);
  $directory = drupal_dirname(file_build_uri('collageformatter/' . file_uri_target($box['uri'])));
  $image_uri = $directory . '/' . $filename;
  if (!file_exists($image_uri)) {
    if (file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
      if ($settings['advanced']['original_image_reference'] == 'symlink') {
        if (!symlink(drupal_realpath($box['uri']), drupal_realpath($image_uri))) {
          watchdog('collageformatter', 'Failed to symlink file @source to @destination.', array(
            '@source' => $box['uri'],
            '@destination' => $image_uri,
          ));
        }
      }
      elseif ($settings['advanced']['original_image_reference'] == 'copy') {
        if (!file_unmanaged_copy($box['uri'], $image_uri, FILE_EXISTS_REPLACE)) {
          watchdog('collageformatter', 'Failed to copy file from @source to @destination.', array(
            '@source' => $box['uri'],
            '@destination' => $image_uri,
          ));
        }
      }
      elseif ($settings['advanced']['original_image_reference'] == 'fake') {
        $image = image_load($box['uri']);
        image_effect_apply($image, array(
          'effect callback' => 'image_scale_effect',
          'data' => array(
            'width' => 1,
            'height' => 1,
          ),
        ));
        image_save($image, $image_uri);
      }
    }
  }
  return $image_uri;
}