From 955fb01ff6d3550ded8253ea17796e146555912b Mon Sep 17 00:00:00 2001 From: airbuzz Date: Fri, 26 Jun 2026 10:33:49 +0900 Subject: [PATCH] Fix: don't force non-crop size slugs to exact dimensions `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 `` 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 --- php/class-media.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/php/class-media.php b/php/class-media.php index 0d919ce2..65a782f1 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -3301,6 +3301,16 @@ public function get_size_from_slug( $size_slug ) { $size_data = $image_subsizes[ $size_slug ]; + // A non-crop ( crop => false ) size is a maximum bounding box, not exact dimensions. + // WordPress scales such images to fit inside the box while preserving the aspect ratio, + // so the registered width/height must not be treated as a fixed crop. Doing so forces + // non-square images into the box dimensions ( e.g. the default `large` 1024x1024 becomes + // w_1024,h_1024,c_scale ), visibly stretching landscape/portrait assets. Only hard-crop + // sizes have exact dimensions worth pinning here. + if ( empty( $size_data['crop'] ) ) { + return null; + } + // Return width and height if both are present and valid. if ( ! empty( $size_data['width'] ) && ! empty( $size_data['height'] ) ) { return array( (int) $size_data['width'], (int) $size_data['height'] );