Merge pull request #18120 from woocommerce/fix/18117

Only resize WC image sizes.
This commit is contained in:
Claudiu Lodromanean 2017-12-12 10:16:39 -08:00 committed by GitHub
commit 71647c1b9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions

View File

@ -58,6 +58,12 @@ class WC_Regenerate_Images {
* @return array
*/
public static function maybe_resize_image( $image, $attachment_id, $size, $icon ) {
// Use a whitelist of sizes we want to resize. Ignore others.
if ( ! in_array( $size, array( 'woocommerce_thumbnail', 'woocommerce_single', 'shop_thumbnail', 'shop_catalog', 'shop_single' ), true ) ) {
return $image;
}
// Get image metadata - we need it to proceed.
$imagemeta = wp_get_attachment_metadata( $attachment_id );
if ( false === $imagemeta || empty( $imagemeta ) ) {
@ -66,11 +72,8 @@ class WC_Regenerate_Images {
$size_settings = wc_get_image_size( $size );
if ( in_array( $size, array( 'woocommerce_thumbnail' ), true ) && isset( $imagemeta['sizes'], $imagemeta['sizes'][ $size ] ) ) {
if ( $imagemeta['sizes'][ $size ]['width'] !== $size_settings['width'] || $imagemeta['sizes'][ $size ]['height'] !== $size_settings['height'] ) {
$image = self::resize_and_return_image( $attachment_id, $image, $size, $icon );
}
} else {
// If size differs from image meta, regen.
if ( isset( $imagemeta['sizes'], $imagemeta['sizes'][ $size ] ) && ( $imagemeta['sizes'][ $size ]['width'] !== $size_settings['width'] || $imagemeta['sizes'][ $size ]['height'] !== $size_settings['height'] ) ) {
$image = self::resize_and_return_image( $attachment_id, $image, $size, $icon );
}