Validates an image uploaded by a user. This is an exact copy of user_validate_picture() except our validator which is added before file_validate_image_resolution(). file_validate_image_resolution resizes the image if it's too large loosing the exif data in the process. The standard validators of hook_file_validate() are run after user_validate_picture() so it cannot be used because the image does not contain the exif data anymore. The only solution is to completely replace the validator from core.

See also

user_validate_picture()

1 string reference to '_exif_orientation_validate_user_picture'
exif_orientation_form_user_profile_form_alter in ./exif_orientation.module
Implements hook_form_alter(). Replace the user_validate_picture validator with our own.

File

./exif_orientation.module, line 28

Code

function _exif_orientation_validate_user_picture(&$form, &$form_state) {
    // If required, validate the uploaded picture.
    $validators = array(
        'file_validate_is_image' => array(),
        '_exif_orientation_validate_image_callback' => array(),
        'file_validate_image_resolution' => array(
            variable_get('user_picture_dimensions', '85x85'),
        ),
        'file_validate_size' => array(
            variable_get('user_picture_file_size', '30') * 1024,
        ),
    );
    // Save the file as a temporary file.
    $file = file_save_upload('picture_upload', $validators);
    if ($file === FALSE) {
        form_set_error('picture_upload', t("Failed to upload the picture image; the %directory directory doesn't exist or is not writable.", array(
            '%directory' => variable_get('user_picture_path', 'pictures'),
        )));
    }
    elseif ($file !== NULL) {
        $form_state['values']['picture_upload'] = $file;
    }
}