Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions php/class-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] );
Expand Down