Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I may be wrong but I think the default file_validate_image_resolution() function is not only doing validation but is also manipulating the uploaded image:
if ($info['width'] > $width || $info['height'] > $height) {
// Try to resize the image to fit the dimensions.
if ($image = image_load($file->uri)) {
image_scale($image, $width, $height);
image_save($image);
$file->filesize = $image->info['file_size'];
drupal_set_message(t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $maximum_dimensions)));
}
else {
$errors[] = t('The image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => $maximum_dimensions));
}
}
In some situation, we only want to check the image resolution fit some requirements without any scale effect.
My suggestion is to add a new file_validate_image_resolution function which only focus on validating the requirements.
Comments
Comment #2
azzida CreditAttribution: azzida commentedI found a functional workaround. We had a hard requirement that a particular image field be restricted to '1564x680' only. Moreso, they wanted to prevent resizing if uploading an image that was too big.
This workaround tested in Drupal 7.51 with Media module 7.x-2.0-beta5.
Comment #3
Daniel Ward CreditAttribution: Daniel Ward commentedCould you do this using hook_entity_form_display_alter()? That would allow you to access the field definitions for your entity type and set some additional resolution settings on the image field. Those settings are enforced by the image widget so you wouldn't need any custom validation. Something like this perhaps:
Comment #4
apadernoI am closing this issue, since the code shown in the IS isn't used from this module.