Skip to content

Commit 5d87d47

Browse files
committed
Apply 40370.diff refresh @6.4.0
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 WordPress#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).
1 parent 35f7b9e commit 5d87d47

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

src/wp-includes/class-wp-image-editor-gd.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,27 @@ protected function update_size( $width = false, $height = false ) {
153153
return parent::update_size( $width, $height );
154154
}
155155

156+
/**
157+
* Sets or updates current image size.
158+
*
159+
* @since 5.1.0
160+
*
161+
* @param bool|array $crop
162+
* @param int $dst_w
163+
* @param int $dst_h
164+
* @return true
165+
*/
166+
protected function create_crop_hash( $crop, $dst_w, $dst_h ) {
167+
if ( ! is_array( $crop ) ) {
168+
return false;
169+
}
170+
171+
$str = $crop[0] . $crop[1] . $dst_w . $dst_h;
172+
$hash = substr( md5( $str ), 0, 8 );
173+
174+
return parent::create_crop_hash( $hash );
175+
}
176+
156177
/**
157178
* Resizes current image.
158179
*
@@ -220,6 +241,7 @@ protected function _resize( $max_w, $max_h, $crop = false ) {
220241
imagecopyresampled( $resized, $this->image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
221242

222243
if ( is_gd_image( $resized ) ) {
244+
$this->create_crop_hash( $crop, $dst_w, $dst_h );
223245
$this->update_size( $dst_w, $dst_h );
224246
return $resized;
225247
}
@@ -534,6 +556,7 @@ protected function _save( $image, $filename = null, $mime_type = null ) {
534556
'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
535557
'width' => $this->size['width'],
536558
'height' => $this->size['height'],
559+
'hash' => $this->hash,
537560
'mime-type' => $mime_type,
538561
'filesize' => wp_filesize( $filename ),
539562
);

src/wp-includes/class-wp-image-editor-imagick.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,27 @@ public static function set_imagick_time_limit() {
309309
}
310310
}
311311

312+
/**
313+
* Sets or updates current image size.
314+
*
315+
* @since 5.1.0
316+
*
317+
* @param bool|array $crop
318+
* @param int $dst_w
319+
* @param int $dst_h
320+
* @return true
321+
*/
322+
protected function create_crop_hash( $crop, $dst_w, $dst_h ) {
323+
if ( ! is_array( $crop ) ) {
324+
return false;
325+
}
326+
327+
$str = $crop[0] . $crop[1] . $dst_w . $dst_h;
328+
$hash = substr( md5( $str ), 0, 8 );
329+
330+
return parent::create_crop_hash( $hash );
331+
}
332+
312333
/**
313334
* Resizes current image.
314335
*
@@ -343,6 +364,7 @@ public function resize( $max_w, $max_h, $crop = false ) {
343364
list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims;
344365

345366
if ( $crop ) {
367+
$this->create_crop_hash( $crop, $dst_w, $dst_h );
346368
return $this->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h );
347369
}
348370

@@ -837,6 +859,7 @@ protected function _save( $image, $filename = null, $mime_type = null ) {
837859
'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
838860
'width' => $this->size['width'],
839861
'height' => $this->size['height'],
862+
'hash' => $this->hash,
840863
'mime-type' => $mime_type,
841864
'filesize' => wp_filesize( $filename ),
842865
);

src/wp-includes/class-wp-image-editor.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
abstract class WP_Image_Editor {
1616
protected $file = null;
1717
protected $size = null;
18+
protected $hash = null;
1819
protected $mime_type = null;
1920
protected $output_mime_type = null;
2021
protected $default_mime_type = 'image/jpeg';
@@ -221,6 +222,31 @@ protected function update_size( $width = null, $height = null ) {
221222
return true;
222223
}
223224

225+
226+
/**
227+
* Gets current image hash (when crop position has been set).
228+
*
229+
* @since 5.1.0
230+
*
231+
* @return string $hash 8 character hash
232+
*/
233+
public function get_crop_hash() {
234+
return $this->hash;
235+
}
236+
237+
/**
238+
* Sets current image hash (when crop position has been set).
239+
*
240+
* @since 5.1.0
241+
*
242+
* @param string $hash
243+
* @return true
244+
*/
245+
protected function create_crop_hash( $hash = null ) {
246+
$this->hash = $hash;
247+
return true;
248+
}
249+
224250
/**
225251
* Gets the Image Compression quality on a 1-100% scale.
226252
*
@@ -486,7 +512,13 @@ public function get_suffix() {
486512
return false;
487513
}
488514

489-
return "{$this->size['width']}x{$this->size['height']}";
515+
$suffix = "{$this->size['width']}x{$this->size['height']}";
516+
517+
if( $this->get_crop_hash() ){
518+
$suffix = $suffix . "-{$this->hash}";
519+
}
520+
521+
return $suffix;
490522
}
491523

492524
/**

0 commit comments

Comments
 (0)