WC_Regenerate_Images::image_size_matches_settings( array $image, string $size )

See if an image’s dimensions match actual settings.


Description Description


Parameters Parameters

$image

(Required) Image dimensions array.

$size

(Required) Named size.


Top ↑

Return Return

(bool) True if they match. False if they do not (may trigger regen).


Top ↑

Source Source

File: includes/class-wc-regenerate-images.php

	protected static function image_size_matches_settings( $image, $size ) {
		$target_size = wc_get_image_size( $size );
		$uncropped   = '' === $target_size['width'] || '' === $target_size['height'];

		if ( ! $uncropped ) {
			$ratio_match = wp_image_matches_ratio( $image['width'], $image['height'], $target_size['width'], $target_size['height'] );

			// Size is invalid if the widths or crop setting don't match.
			if ( $ratio_match && $target_size['width'] !== $image['width'] ) {
				return false;
			}

			// Size is invalid if the heights don't match.
			if ( $ratio_match && $target_size['height'] && $target_size['height'] !== $image['height'] ) {
				return false;
			}
		}

		// If cropping mode has changed, regenerate the image.
		if ( $uncropped && empty( $image['uncropped'] ) ) {
			return false;
		}

		return true;
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.