diff --git a/src/wp-includes/class-wp-image-editor-gd.php b/src/wp-includes/class-wp-image-editor-gd.php
index 32f33dfa6e..13fe637053 100644
|
a
|
b
|
class WP_Image_Editor_GD extends WP_Image_Editor { |
| 136 | 136 | return parent::update_size( $width, $height ); |
| 137 | 137 | } |
| 138 | 138 | |
| | 139 | /** |
| | 140 | * Sets or updates current image size. |
| | 141 | * |
| | 142 | * @since 5.1.0 |
| | 143 | * |
| | 144 | * @param bool|array $crop |
| | 145 | * @param int $dst_w |
| | 146 | * @param int $dst_h |
| | 147 | * @return true |
| | 148 | */ |
| | 149 | protected function update_crop_hash( $crop, $dst_w, $dst_h ) { |
| | 150 | if ( ! is_array($crop) ) { |
| | 151 | return false; |
| | 152 | } |
| | 153 | |
| | 154 | $str = $crop[0] . $crop[1] . $dst_w . $dst_h; |
| | 155 | $hash = substr( md5( $str ), 0, 8 ); |
| | 156 | |
| | 157 | return parent::update_crop_hash( $hash ); |
| | 158 | } |
| | 159 | |
| 139 | 160 | /** |
| 140 | 161 | * Resizes current image. |
| 141 | 162 | * Wraps _resize, since _resize returns a GD Resource. |
| … |
… |
class WP_Image_Editor_GD extends WP_Image_Editor { |
| 187 | 208 | imagecopyresampled( $resized, $this->image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); |
| 188 | 209 | |
| 189 | 210 | if ( is_resource( $resized ) ) { |
| | 211 | $this->update_crop_hash( $crop, $dst_w, $dst_h ); |
| 190 | 212 | $this->update_size( $dst_w, $dst_h ); |
| 191 | 213 | return $resized; |
| 192 | 214 | } |
| … |
… |
class WP_Image_Editor_GD extends WP_Image_Editor { |
| 217 | 239 | * @return array An array of resized images' metadata by size. |
| 218 | 240 | */ |
| 219 | 241 | public function multi_resize( $sizes ) { |
| | 242 | |
| 220 | 243 | $metadata = array(); |
| 221 | 244 | $orig_size = $this->size; |
| 222 | 245 | |
| … |
… |
class WP_Image_Editor_GD extends WP_Image_Editor { |
| 429 | 452 | 'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ), |
| 430 | 453 | 'width' => $this->size['width'], |
| 431 | 454 | 'height' => $this->size['height'], |
| | 455 | 'hash' => $this->hash, |
| 432 | 456 | 'mime-type' => $mime_type, |
| 433 | 457 | ); |
| 434 | 458 | } |
diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php
index abb215038b..e1f304ffb9 100644
|
a
|
b
|
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
| 237 | 237 | return parent::update_size( $width, $height ); |
| 238 | 238 | } |
| 239 | 239 | |
| | 240 | /** |
| | 241 | * Sets or updates current image size. |
| | 242 | * |
| | 243 | * @since 5.1.0 |
| | 244 | * |
| | 245 | * @param bool|array $crop |
| | 246 | * @param int $dst_w |
| | 247 | * @param int $dst_h |
| | 248 | * @return true |
| | 249 | */ |
| | 250 | protected function update_crop_hash( $crop, $dst_w, $dst_h ) { |
| | 251 | if ( ! is_array($crop) ) { |
| | 252 | return false; |
| | 253 | } |
| | 254 | |
| | 255 | $str = $crop[0] . $crop[1] . $dst_w . $dst_h; |
| | 256 | $hash = substr( md5( $str ), 0, 8 ); |
| | 257 | |
| | 258 | return parent::update_crop_hash( $hash ); |
| | 259 | } |
| | 260 | |
| 240 | 261 | /** |
| 241 | 262 | * Resizes current image. |
| 242 | 263 | * |
| … |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
| 263 | 284 | list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims; |
| 264 | 285 | |
| 265 | 286 | if ( $crop ) { |
| | 287 | $this->update_crop_hash( $crop, $dst_w, $dst_h ); |
| 266 | 288 | return $this->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h ); |
| 267 | 289 | } |
| 268 | 290 | |
| … |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
| 646 | 668 | 'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ), |
| 647 | 669 | 'width' => $this->size['width'], |
| 648 | 670 | 'height' => $this->size['height'], |
| | 671 | 'hash' => $this->hash, |
| 649 | 672 | 'mime-type' => $mime_type, |
| 650 | 673 | ); |
| 651 | 674 | } |
diff --git a/src/wp-includes/class-wp-image-editor.php b/src/wp-includes/class-wp-image-editor.php
index 26dd78d230..c7b4d2c907 100644
|
a
|
b
|
|
| 14 | 14 | abstract class WP_Image_Editor { |
| 15 | 15 | protected $file = null; |
| 16 | 16 | protected $size = null; |
| | 17 | protected $hash = null; |
| 17 | 18 | protected $mime_type = null; |
| 18 | 19 | protected $default_mime_type = 'image/jpeg'; |
| 19 | 20 | protected $quality = false; |
| … |
… |
abstract class WP_Image_Editor { |
| 195 | 196 | return true; |
| 196 | 197 | } |
| 197 | 198 | |
| | 199 | |
| | 200 | /** |
| | 201 | * Gets current image hash (when crop position has been set). |
| | 202 | * |
| | 203 | * @since 5.1.0 |
| | 204 | * |
| | 205 | * @return string $hash 8 character hash |
| | 206 | */ |
| | 207 | public function get_crop_hash() { |
| | 208 | return $this->hash; |
| | 209 | } |
| | 210 | |
| | 211 | /** |
| | 212 | * Sets current image hash (when crop position has been set). |
| | 213 | * |
| | 214 | * @since 5.1.0 |
| | 215 | * |
| | 216 | * @param string $hash |
| | 217 | * @return true |
| | 218 | */ |
| | 219 | protected function update_crop_hash( $hash = null ) { |
| | 220 | $this->hash = $hash; |
| | 221 | return true; |
| | 222 | } |
| | 223 | |
| 198 | 224 | /** |
| 199 | 225 | * Gets the Image Compression quality on a 1-100% scale. |
| 200 | 226 | * |
| … |
… |
abstract class WP_Image_Editor { |
| 378 | 404 | return false; |
| 379 | 405 | } |
| 380 | 406 | |
| 381 | | return "{$this->size['width']}x{$this->size['height']}"; |
| | 407 | $suffix = "{$this->size['width']}x{$this->size['height']}"; |
| | 408 | |
| | 409 | if( $this->get_crop_hash() ){ |
| | 410 | $suffix = $suffix . "-{$this->hash}"; |
| | 411 | } |
| | 412 | |
| | 413 | return $suffix; |
| 382 | 414 | } |
| 383 | 415 | |
| 384 | 416 | /** |