You are here

function _epsacrop_create_thumb in EPSA Crop - Image Cropping 6

Same name and namespace in other branches
  1. 6.2 epsacrop.module \_epsacrop_create_thumb()
1 call to _epsacrop_create_thumb()
_epsacrop_thumb_filepath in ./epsacrop.module

File

./epsacrop.module, line 341
The main file of module

Code

function _epsacrop_create_thumb($source, $destination) {
  if (!is_file($source)) {
    return FALSE;
  }
  $info = image_get_info($source);
  $size = explode('x', variable_get('epsacrop_box_size', '512x384'));
  if (is_file($destination)) {
    $thumb = image_get_info($destination);
    if ($thumb['width'] != $size[0] && $thumb['height'] != $size[1] && ($info['width'] > $size[0] || $info['height'] > $size[1])) {
      unlink($destination);
    }
    else {
      return;
    }
  }
  $directories = explode('/', $destination);
  array_pop($directories);
  $file_system = file_directory_path();
  foreach ($directories as $directory) {
    $full_path = isset($full_path) ? $full_path . '/' . $directory : $directory;
    if (strpos($full_path, $file_system) === 0) {
      field_file_check_directory($full_path, FILE_CREATE_DIRECTORY);
    }
  }
  if ($info['width'] <= $size[0] && $info['height'] <= $size[1]) {
    file_copy($source, $destination);
  }
  elseif (image_get_toolkit() && @image_scale($source, $destination, $size[0], $size[1])) {
    @chmod($destination, 0644);
  }
  else {
    drupal_set_message(t("An image thumbnail was not able to be created."), 'error');
  }
}