From 5d87d471c6d3b5b47c0177609c90bd3d3b150841 Mon Sep 17 00:00:00 2001 From: Pea Date: Thu, 24 Aug 2023 15:08:03 -0400 Subject: [PATCH] Apply 40370.diff refresh @6.4.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 40370.diff​ (4.7 KB) - added by thema ttroyal 5 years ago. patching file src/wp-includes/class-wp-image-editor-gd.php Hunk #1 succeeded at 153 with fuzz 1 (offset 17 lines). Hunk #2 FAILED at 225. Hunk #3 FAILED at 256. Hunk #4 succeeded at 557 with fuzz 2 (offset 105 lines). 2 out of 4 hunks FAILED patching file src/wp-includes/class-wp-image-editor-imagick.php Hunk #1 succeeded at 309 with fuzz 1 (offset 72 lines). Hunk #2 succeeded at 364 (offset 80 lines). Hunk #3 succeeded at 859 with fuzz 2 (offset 191 lines). patching file src/wp-includes/class-wp-image-editor.php Hunk #1 succeeded at 15 with fuzz 2 (offset 1 line). Hunk #2 succeeded at 222 (offset 26 lines). Hunk #3 succeeded at 512 (offset 108 lines). --- src/wp-includes/class-wp-image-editor-gd.php | 23 +++++++++++++ .../class-wp-image-editor-imagick.php | 23 +++++++++++++ src/wp-includes/class-wp-image-editor.php | 34 ++++++++++++++++++- 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-image-editor-gd.php b/src/wp-includes/class-wp-image-editor-gd.php index de079357fb860..2465e055f2964 100644 --- a/src/wp-includes/class-wp-image-editor-gd.php +++ b/src/wp-includes/class-wp-image-editor-gd.php @@ -153,6 +153,27 @@ protected function update_size( $width = false, $height = false ) { return parent::update_size( $width, $height ); } + /** + * Sets or updates current image size. + * + * @since 5.1.0 + * + * @param bool|array $crop + * @param int $dst_w + * @param int $dst_h + * @return true + */ + protected function create_crop_hash( $crop, $dst_w, $dst_h ) { + if ( ! is_array( $crop ) ) { + return false; + } + + $str = $crop[0] . $crop[1] . $dst_w . $dst_h; + $hash = substr( md5( $str ), 0, 8 ); + + return parent::create_crop_hash( $hash ); + } + /** * Resizes current image. * @@ -220,6 +241,7 @@ protected function _resize( $max_w, $max_h, $crop = false ) { imagecopyresampled( $resized, $this->image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); if ( is_gd_image( $resized ) ) { + $this->create_crop_hash( $crop, $dst_w, $dst_h ); $this->update_size( $dst_w, $dst_h ); return $resized; } @@ -534,6 +556,7 @@ protected function _save( $image, $filename = null, $mime_type = null ) { 'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ), 'width' => $this->size['width'], 'height' => $this->size['height'], + 'hash' => $this->hash, 'mime-type' => $mime_type, 'filesize' => wp_filesize( $filename ), ); diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php index 7229c903b40a0..418b85a8fdd7e 100644 --- a/src/wp-includes/class-wp-image-editor-imagick.php +++ b/src/wp-includes/class-wp-image-editor-imagick.php @@ -309,6 +309,27 @@ public static function set_imagick_time_limit() { } } + /** + * Sets or updates current image size. + * + * @since 5.1.0 + * + * @param bool|array $crop + * @param int $dst_w + * @param int $dst_h + * @return true + */ + protected function create_crop_hash( $crop, $dst_w, $dst_h ) { + if ( ! is_array( $crop ) ) { + return false; + } + + $str = $crop[0] . $crop[1] . $dst_w . $dst_h; + $hash = substr( md5( $str ), 0, 8 ); + + return parent::create_crop_hash( $hash ); + } + /** * Resizes current image. * @@ -343,6 +364,7 @@ public function resize( $max_w, $max_h, $crop = false ) { list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims; if ( $crop ) { + $this->create_crop_hash( $crop, $dst_w, $dst_h ); return $this->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h ); } @@ -837,6 +859,7 @@ protected function _save( $image, $filename = null, $mime_type = null ) { 'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ), 'width' => $this->size['width'], 'height' => $this->size['height'], + 'hash' => $this->hash, 'mime-type' => $mime_type, 'filesize' => wp_filesize( $filename ), ); diff --git a/src/wp-includes/class-wp-image-editor.php b/src/wp-includes/class-wp-image-editor.php index bb15a03a0747c..c6f116976043d 100644 --- a/src/wp-includes/class-wp-image-editor.php +++ b/src/wp-includes/class-wp-image-editor.php @@ -15,6 +15,7 @@ abstract class WP_Image_Editor { protected $file = null; protected $size = null; + protected $hash = null; protected $mime_type = null; protected $output_mime_type = null; protected $default_mime_type = 'image/jpeg'; @@ -221,6 +222,31 @@ protected function update_size( $width = null, $height = null ) { return true; } + + /** + * Gets current image hash (when crop position has been set). + * + * @since 5.1.0 + * + * @return string $hash 8 character hash + */ + public function get_crop_hash() { + return $this->hash; + } + + /** + * Sets current image hash (when crop position has been set). + * + * @since 5.1.0 + * + * @param string $hash + * @return true + */ + protected function create_crop_hash( $hash = null ) { + $this->hash = $hash; + return true; + } + /** * Gets the Image Compression quality on a 1-100% scale. * @@ -486,7 +512,13 @@ public function get_suffix() { return false; } - return "{$this->size['width']}x{$this->size['height']}"; + $suffix = "{$this->size['width']}x{$this->size['height']}"; + + if( $this->get_crop_hash() ){ + $suffix = $suffix . "-{$this->hash}"; + } + + return $suffix; } /**