Skip intermediate sizes of a different aspect ratio than the original image when considering which image to use in image_get_intermediate_size(). fixes #12218
git-svn-id: http://svn.automattic.com/wordpress/trunk@13145 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
8e48c44de4
commit
3284d920c0
|
@ -484,6 +484,13 @@ function image_get_intermediate_size($post_id, $size='thumbnail') {
|
||||||
foreach ( $areas as $_size ) {
|
foreach ( $areas as $_size ) {
|
||||||
$data = $imagedata['sizes'][$_size];
|
$data = $imagedata['sizes'][$_size];
|
||||||
if ( $data['width'] >= $size[0] || $data['height'] >= $size[1] ) {
|
if ( $data['width'] >= $size[0] || $data['height'] >= $size[1] ) {
|
||||||
|
// Skip images with unexpectedly divergent aspect ratios (crops)
|
||||||
|
// First, we calculate what size the original image would be if constrained to a box the size of the current image in the loop
|
||||||
|
$maybe_cropped = image_resize_dimensions($imagedata['width'], $imagedata['height'], $data['width'], $data['height'], false );
|
||||||
|
// 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
|
||||||
|
if ( 'thumbnail' != $_size && ( !$maybe_cropped || $maybe_cropped[0] != $data['width'] || $maybe_cropped[1] != $data['height'] ) )
|
||||||
|
continue;
|
||||||
|
// If we're still here, then we're going to use this size
|
||||||
$file = $data['file'];
|
$file = $data['file'];
|
||||||
list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
|
list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
|
||||||
return compact( 'file', 'width', 'height' );
|
return compact( 'file', 'width', 'height' );
|
||||||
|
|
Loading…
Reference in New Issue