Fix: don't force non-crop size slugs to exact dimensions#1190
Open
airbuzz wants to merge 1 commit into
Open
Conversation
`get_size_from_slug()` returned the registered width/height from `wp_get_registered_image_subsizes()` for any matching slug, ignoring the `crop` flag. For non-crop sizes ( crop => false ) those values are a maximum bounding box, not exact dimensions: WordPress scales the image to fit inside the box while preserving aspect ratio. Treating them as a fixed crop made the delivery layer emit, for the default `large` ( 1024x1024, crop => false ), a transformation of `w_1024,h_1024,c_scale` applied to a landscape/portrait source, visibly stretching it into a square. This surfaced on blocks whose stored `<img src>` had no size suffix (so the URL-based size lookup returned nothing and the figure-class slug fallback ran). Return early for non-crop sizes so only genuine hard-crop sizes are pinned to exact dimensions. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
get_size_from_slug()returned the registered width/height fromwp_get_registered_image_subsizes()for any matching slug, ignoring thecropflag. For non-crop sizes ( crop => false ) those values are a maximum bounding box, not exact dimensions: WordPress scales the image to fit inside the box while preserving aspect ratio.Treating them as a fixed crop made the delivery layer emit, for the default
large( 1024x1024, crop => false ), a transformation ofw_1024,h_1024,c_scaleapplied to a landscape/portrait source, visibly stretching it into a square. This surfaced on blocks whose stored<img src>had no size suffix (so the URL-based size lookup returned nothing and the figure-class slug fallback ran).Return early for non-crop sizes so only genuine hard-crop sizes are pinned to exact dimensions.
Fixes #123
Approach
QA notes