You are here

function avatar_selection_validate_picture in Avatar Selection 5.2

Same name and namespace in other branches
  1. 5 avatar_selection.module \avatar_selection_validate_picture()

Validate the picture.

1 call to avatar_selection_validate_picture()
avatar_selection_upload_form_validate in ./avatar_selection.module
Validate and upload the image.

File

./avatar_selection.module, line 956
The Avatar Selection module allows the user to pick an avatar image from a list already loaded by an administrative user, and to the administrator to disable uploading other avatar files by the user.

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.'));
  }
  elseif (image_get_toolkit()) {
    image_scale($file->filepath, $file->filepath, $maxwidth, $maxheight);
  }
  elseif (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),
    )));
  }
  elseif ($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'),
    )));
  }
}