Go to file
Joe McGill a91e769e36 Media: Prevent `image_get_intermediate_size()` from returning cropped images.
When `$size` is passed to `image_get_intermediate_size()` as an array of width
and height values and an exact image size matching those values isn't available,
the function loops through the available attachment sizes and returns the
smallest image larger than the requested dimensions with the same aspect ratio.

The aspect ratio check is skipped for the 'thumbnail' size to provide a fallback
for small sizes when no other image option is available. This resulted in a poor
selection when the size requested was smaller than the 'thumbnail' dimensions
but a larger size matching the requested ratio existed.

This refactors the internals of `image_get_intermediate_size()` to ensure the
'thumbnail' size is only returned as a fallback to small sizes once all other
options have been considered, and makes the control flow easier to follow.

This also introduces a new helper function, `wp_image_matches_ratio()` for
testing whether the aspect ratios of two sets of dimensions match. This function
is also now used in `wp_calculate_image_srcset()` during the selection process.

Props flixos, joemcgill.
Fixes #34384, #34980.

git-svn-id: https://develop.svn.wordpress.org/trunk@38086 602fd350-edb4-49c9-b593-d223f7449a82
2016-07-18 02:13:45 +00:00
src Media: Prevent `image_get_intermediate_size()` from returning cropped images. 2016-07-18 02:13:45 +00:00
tests Media: Prevent `image_get_intermediate_size()` from returning cropped images. 2016-07-18 02:13:45 +00:00
tools/i18n DOCS: Replace HTTP links with HTTPS. 2016-06-10 04:49:09 +00:00
.editorconfig
.gitignore Remove accidental .svn addition to .gitignore 2015-12-12 18:26:22 +00:00
.jshintrc Build: Prevent non-breaking spaces from accidentally being inserted into JavaScript files. 2015-11-12 12:04:55 +00:00
.travis.yml Output node and npm versions on travis 2016-06-16 17:27:22 +00:00
Gruntfile.js Grunt: when running `precommit` use regex to check which files have been modified. 2016-06-19 12:31:15 +00:00
package.json Update grunt-patch-wordpress to 0.4.0 2016-06-01 21:24:09 +00:00
phpunit.xml.dist Set a whitelist for PHPUnit code coverage. 2016-05-17 20:22:57 +00:00
wp-cli.yml Remove debug mode from WP-CLI by default, as it now outputs too much debugging information to be of use during normal development. 2015-11-28 18:36:06 +00:00
wp-config-sample.php Lightly clean up and improve inline documentation in wp-config-sample.php. 2015-05-10 00:05:30 +00:00
wp-tests-config-sample.php Unit Tests: Correct comment in `wp-tests-config-sample.php`. 2016-01-21 20:24:12 +00:00