Image metadata incorrect when larger than 2650, causing crop issues
-
I have discovered that images larger than 2560px cause a mismatch with image metadata stored in the database. This causes an issue when using another plugin (Crop-Thumbnails) that allows for precise crop framing. In the image below, you can see on the left the final crop output, which does not match my crop selection in the left side. I believe this is because WordPress still has the image dimensions saved as
2560x1707
(also visible in the screenshot) but in reality the scaled image file has been removed and the full5367x3578
image is used instead.I double-checked the image meta in the database to confirm:
Array ( // this is the width of the scaled file, the original is actually 5367 [width] => 2560 [height] => 1707 //
-scaled
is missing from the filename [file] => 2023/03/pexels-andrey-grushnikov-940034.jpg [filesize] => 890443 // this filesize is also for the scaled version [sizes] => Array ( [medium] => Array ( [file] => pexels-andrey-grushnikov-940034-300x200.jpg [width] => 300 [height] => 200 [mime-type] => image/jpeg [filesize] => 18065 ) // other sizes... ) )Here are details on my local environment used to troubleshoot this if it helps:
- WordPress 6.1.1 (also tested with WP 6.2)
- PHP 7.4.30 (also tested with PHP 8)
- Plugin: Image Regenerate & Select Crop 7.0.1
- Plugin: Crop Thumbnails 1.4.0
- Test image used: https://www.pexels.com/photo/photo-of-a-person-holding-an-umbrella-940034/
Reviewing the changelog for this plugin I found a note about the scaled size:
6.2.0 – Tested up to 5.8.2, placeholder fallback, change filter priority to apply earlier the available sizes, fix warnings for info not available in some of the core versions, fix warnings for estimated sizes missing width or height, attempt to bypass scaled size naming, updated sizes filter for backward compatibility, logs length limit, log the WP-CLI command executions, styles adjustments
This is only an issue when images larger than 2650 are uploaded (which is when WP tries to make a ‘scaled’ version) so most of the time it is not a big deal, but there is a chance some editors on the sites I maintain may upload larger sizes without realizing. Is it possible to bypass this removal of ‘scaled’? I did not see a hook or setting in the admin that was related here, but might be nice. In my case I would like to keep the default WordPress functionality and the ‘scaled’ size it creates, along with everything else your great plugin does.
Otherwise, I think the metadata for the image should stay in sync if the ‘scaled’ version is removed. I think this change would also fix the problem I am having when trying to do a custom crop through this Crop-Thumbnails plugin even if I cannot use the ‘scaled’ size with your plugin.
- The topic ‘Image metadata incorrect when larger than 2650, causing crop issues’ is closed to new replies.