You are here

function reg_with_pic_validate_picture in Register with Picture 5

Picture validation taken from user module. We re-wrote the function here because the original function copied in here. The problem is that we didn't have the userid at the time of registration so we took that out and write the picture in the insert case of the user hook.

1 call to reg_with_pic_validate_picture()
reg_with_pic_user in ./reg_with_pic.module
Implementation of hook_user()

File

./reg_with_pic.module, line 49
This module allows a user picture to be uploaded at registration time.

Code

function reg_with_pic_validate_picture($file, &$edit, $user) {
  global $form_values;

  // Initialize the picture:
  $form_values['picture'] = $user->picture;

  // 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_register', 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_register', 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_register', t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array(
            '%dimensions' => variable_get('user_picture_dimensions', '85x85'),
          )));
        }
      }
    }
  }
}