Merged in feature/81-dev-dev01 (pull request #5)

auto-patch  81-dev-dev01-2023-12-05T22_45_26

* auto-patch  81-dev-dev01-2023-12-05T22_45_26
This commit is contained in:
Tony Volpe
2023-12-05 23:05:59 +00:00
parent ba16964e7a
commit 725d3043d5
1463 changed files with 142461 additions and 89421 deletions

View File

@@ -168,6 +168,10 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
$this->image->setIteratorIndex( 0 );
}
if ( 'pdf' === $file_extension ) {
$this->remove_pdf_alpha_channel();
}
$this->mime_type = $this->get_mime_type( $this->image->getImageFormat() );
} catch ( Exception $e ) {
return new WP_Error( 'invalid_image', $e->getMessage(), $this->file );
@@ -316,7 +320,14 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
*
* @param int|null $max_w Image width.
* @param int|null $max_h Image height.
* @param bool|array $crop
* @param bool|array $crop {
* Optional. Image cropping behavior. If false, the image will be scaled (default).
* If true, image will be cropped to the specified dimensions using center positions.
* If an array, the image will be cropped using the array to specify the crop location:
*
* @type string $0 The x crop position. Accepts 'left' 'center', or 'right'.
* @type string $1 The y crop position. Accepts 'top', 'center', or 'bottom'.
* }
* @return true|WP_Error
*/
public function resize( $max_w, $max_h, $crop = false ) {
@@ -751,6 +762,24 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
return $saved;
}
/**
* Removes PDF alpha after it's been read.
*
* @since 6.4.0
*/
protected function remove_pdf_alpha_channel() {
$version = Imagick::getVersion();
// Remove alpha channel if possible to avoid black backgrounds for Ghostscript >= 9.14. RemoveAlphaChannel added in ImageMagick 6.7.5.
if ( $version['versionNumber'] >= 0x675 ) {
try {
// Imagick::ALPHACHANNEL_REMOVE mapped to RemoveAlphaChannel in PHP imagick 3.2.0b2.
$this->image->setImageAlphaChannel( defined( 'Imagick::ALPHACHANNEL_REMOVE' ) ? Imagick::ALPHACHANNEL_REMOVE : 12 );
} catch ( Exception $e ) {
return new WP_Error( 'pdf_alpha_process_failed', $e->getMessage() );
}
}
}
/**
* @since 3.5.0
* @since 6.0.0 The `$filesize` value was added to the returned array.
@@ -1014,5 +1043,4 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
return true;
}
}