Ticket #12218: do_not_use_crops_for_image_get_intermediate_size.diff

File do_not_use_crops_for_image_get_intermediate_size.diff, 1.2 KB (added by markjaquith, 3 years ago)
Line 
1Index: wp-includes/media.php
2===================================================================
3--- wp-includes/media.php       (revision 13140)
4+++ wp-includes/media.php       (working copy)
5@@ -484,6 +484,13 @@
6                        foreach ( $areas as $_size ) {
7                                $data = $imagedata['sizes'][$_size];
8                                if ( $data['width'] >= $size[0] || $data['height'] >= $size[1] ) {
9+                                       // Skip images with unexpectedly divergent aspect ratios (crops)
10+                                       // First, we calculate what size the original image would be if constrained to a box the size of the current image in the loop
11+                                       $maybe_cropped = image_resize_dimensions($imagedata['width'], $imagedata['height'], $data['width'], $data['height'], false );
12+                                       // If the size doesn't match exactly, then it is of a different aspect ratio, so we skip it, unless it's the thumbnail size
13+                                       if ( 'thumbnail' != $_size && ( !$maybe_cropped || $maybe_cropped[0] != $data['width'] || $maybe_cropped[1] != $data['height'] ) )
14+                                               continue;
15+                                       // If we're still here, then we're going to use this size
16                                        $file = $data['file'];
17                                        list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
18                                        return compact( 'file', 'width', 'height' );