From fed3b8fd1f12d037090e9b9d7b60954bc2133b58 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 27 Feb 2015 19:37:47 +0000 Subject: [PATCH] In the `->multi_resize()` method of the `WP_Image_Editor` subclasses, when looping through potential crops, we need to make sure the crop isn't the exact same dimensions as the original image before copying it as a new crop. This ensures that we don't save multiple copies of the same image. Supposedly broke in [30639], but this logic was always missing. When I tested reverting [30639], there were still 2 files being created. Fixes #31296. git-svn-id: https://develop.svn.wordpress.org/trunk@31576 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-image-editor-gd.php | 3 ++- src/wp-includes/class-wp-image-editor-imagick.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-image-editor-gd.php b/src/wp-includes/class-wp-image-editor-gd.php index 37598b2a5e..371552c28c 100644 --- a/src/wp-includes/class-wp-image-editor-gd.php +++ b/src/wp-includes/class-wp-image-editor-gd.php @@ -231,8 +231,9 @@ class WP_Image_Editor_GD extends WP_Image_Editor { } $image = $this->_resize( $size_data['width'], $size_data['height'], $size_data['crop'] ); + $duplicate = ( ( $orig_size['width'] == $size_data['width'] ) && ( $orig_size['height'] == $size_data['height'] ) ); - if( ! is_wp_error( $image ) ) { + if ( ! is_wp_error( $image ) && ! $duplicate ) { $resized = $this->_save( $image ); imagedestroy( $image ); diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php index 5dc326f021..a70bebdaeb 100644 --- a/src/wp-includes/class-wp-image-editor-imagick.php +++ b/src/wp-includes/class-wp-image-editor-imagick.php @@ -301,8 +301,9 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { } $resize_result = $this->resize( $size_data['width'], $size_data['height'], $size_data['crop'] ); + $duplicate = ( ( $orig_size['width'] == $size_data['width'] ) && ( $orig_size['height'] == $size_data['height'] ) ); - if( ! is_wp_error( $resize_result ) ) { + if ( ! is_wp_error( $resize_result ) && ! $duplicate ) { $resized = $this->_save( $this->image ); $this->image->clear();