Skip to content

Commit

Permalink
Apply 40370.diff refresh @6.4.0
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
misfist committed Aug 24, 2023
1 parent 35f7b9e commit 5d87d47
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/wp-includes/class-wp-image-editor-gd.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 ),
);
Expand Down
23 changes: 23 additions & 0 deletions src/wp-includes/class-wp-image-editor-imagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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 ),
);
Expand Down
34 changes: 33 additions & 1 deletion src/wp-includes/class-wp-image-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 5d87d47

Please sign in to comment.