Skip to content

Fix: don't force non-crop size slugs to exact dimensions#1190

Open
airbuzz wants to merge 1 commit into
cloudinary:masterfrom
airbuzz:fix/size-slug-non-crop-stretch
Open

Fix: don't force non-crop size slugs to exact dimensions#1190
airbuzz wants to merge 1 commit into
cloudinary:masterfrom
airbuzz:fix/size-slug-non-crop-stretch

Conversation

@airbuzz

@airbuzz airbuzz commented Jun 26, 2026

Copy link
Copy Markdown

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.

Fixes #123

Approach

  • Describe the approach and the suggested implementation.

QA notes

  • Detail the steps needed to verify the PR.

`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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant