file_validate_image_resolution() doesn't recalculate the image dimensions after checking $maximum_dimensions

Created on 24 January 2014, over 10 years ago
Updated 5 January 2024, 5 months ago

Function file_validate_image_resolution() can receive $maximum_dimensions and/or $minimum_dimensions restrictions.

When both ($maximum_dimensions and $minimum_dimensions) are sent, it calculates the image width and height from the original file. Then it checks the the new image to see if $maximum_dimensions are fine, and if not, it scales the image (I'd like this behaviour to be optional, but it is out of this topic). After scaling the image, obviously both width and height are smaller than the original ones. Then it checks if the $minimum_dimensions are fine, but it doesn't recalculate the width and height from the new image, it checks the $minimum_dimensions against the original image dimensions, this is wrong.

Here is a little example:
- $maximum_dimensions = 1000x1000
- $minimum_dimensions = 500x500
- Original file dimensions = 3000 x 750

After checking $maximum_dimensions, it scales the image to fit there.
- Scaled image dimensions = 1000x250

After checking $minimum_dimensions (500x500) it shouldn't be validated because the new scaled image height (250) is smaller than the minimum height required (500), but it is validated because it is being compared with the original image height (750).

The solution is to recalculate the $info variable (that holds width and height information) with the information from the scaled image before to check $minimum_dimensions.

🐛 Bug report
Status

Fixed

Version

7.0 ⚰️

Component
File system 

Last updated about 12 hours ago

Created by

🇨🇴Colombia juankvillegas

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024