Skip to content

Commit

Permalink
#40370 - Refresh against [email protected]
Browse files Browse the repository at this point in the history
Fix incompatible declarations PHP War
nings - patch.diff​ (1.9 KB) - added by davidbawiec 3 years ago.
patching file wp-includes/class-wp-image-editor-gd.php
Hunk #1 FAILED at 154.
Hunk #2 FAILED at 218.
2 out of 2 hunks FAILED
patching file wp-includes/class-wp-image-editor-imagick.php
Hunk #1 FAILED at 251.
Hunk #2 succeeded at 364 (offset 75 lines).
1 out of 2 hunks FAILED
  • Loading branch information
misfist committed Aug 24, 2023
1 parent 35f7b9e commit 5ed6c1a
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
22 changes: 22 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 @@ -534,6 +555,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 5ed6c1a

Please sign in to comment.