You are here

function imagefield_crop_upload_validate in Imagefield Crop 7.2

Same name and namespace in other branches
  1. 7.3 imagefield_crop.module \imagefield_crop_upload_validate()

Validate function for images to be cropped.

Returns an error if output resolution for field is set, but file is smaller.

Return value

array

File

./imagefield_crop.module, line 1009
Functionality and Drupal hook implementations for the Imagefield Crop module.

Code

function imagefield_crop_upload_validate($file, $field, $instance) {
  $errors = array();
  $widget_settings = $instance['widget']['settings'];
  $info = image_get_info($file->uri);
  if (!$info) {
    $errors[] = t('Image seems to be broken and can\'t be processed. Please try to upload another image or resave this current image with graphic editor');
  }
  elseif ($info && $widget_settings['validate_resolution'] && $widget_settings['enforce_ratio'] && !empty($widget_settings['resolution'])) {
    list($width, $height) = explode('x', $widget_settings['resolution']);
    if ($info['width'] < $width || $info['height'] < $height) {
      $errors[] = t('The image is too small; the minimum dimensions are %dimensions pixels.', array(
        '%dimensions' => $widget_settings['resolution'],
      ));
    }
  }
  if ($instance['settings']['max_filesize'] && parse_size($instance['settings']['max_filesize']) < $file->filesize) {
    $errors[] = t('This image is too large.  The maximum size is !max', array(
      '!max' => $instance['settings']['max_filesize'],
    ));
  }
  return $errors;
}