WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/07/2019 01:33:16 AM (6 weeks ago)
Author:
azaozz
Message:

Media: Improve handling of cases where an uploaded image matches exactly a defined intermediate size. In most of these cases the original image has been edited by the user and is "web ready", there is no need for an identical intermediate image.

Introduces the wp_image_resize_identical_dimensions filter so plugins and themes can determine whether a new image with identical dimensions should be created, defaults to false.

Props wpdennis, HKandulla, galbaras, azaozz.
See #32437.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r45932 r46077  
    73177317    return empty( $required ) || version_compare( phpversion(), $required, '>=' );
    73187318}
     7319
     7320/**
     7321 * Check if two numbers are nearly the same.
     7322 *
     7323 * This is similar to using `round()` but the precision is more fine-grained.
     7324 *
     7325 * @since 5.3.0
     7326 *
     7327 * @param int|float $expected  The expected value.
     7328 * @param int|float $actual    The actual number.
     7329 * @param int|float $precision The allowed variation.
     7330 * @return bool Whether the numbers match whithin the specified precision.
     7331 */
     7332function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) {
     7333    return abs( (float) $expected - (float) $actual ) <= $precision;
     7334}
Note: See TracChangeset for help on using the changeset viewer.