You are here

function avatar_selection_validate_picture in Avatar Selection 5

Same name and namespace in other branches
  1. 5.2 avatar_selection.module \avatar_selection_validate_picture()
1 call to avatar_selection_validate_picture()
avatar_selection_images_form_validate in ./avatar_selection.module
Validate the submission.

File

./avatar_selection.module, line 557

Code

function avatar_selection_validate_picture($file) {
  global $form_values;

  // Check that uploaded file is an image, with a maximum file size
  // and maximum height/width.
  $info = image_get_info($file->filepath);
  list($maxwidth, $maxheight) = explode('x', variable_get('user_picture_dimensions', '85x85'));
  if (!$info || !$info['extension']) {
    form_set_error('picture_upload', t('The uploaded file was not an image.'));
  }
  else {
    if (image_get_toolkit()) {
      image_scale($file->filepath, $file->filepath, $maxwidth, $maxheight);
    }
    else {
      if (filesize($file->filepath) > variable_get('user_picture_file_size', '30') * 1000) {
        form_set_error('picture_upload', t('The uploaded image is too large; the maximum file size is %size kB.', array(
          '%size' => variable_get('user_picture_file_size', '30'),
        )));
      }
      else {
        if ($info['width'] > $maxwidth || $info['height'] > $maxheight) {
          form_set_error('picture_upload', t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array(
            '%dimensions' => variable_get('user_picture_dimensions', '85x85'),
          )));
        }
      }
    }
  }
}