W3cubDocs

/WordPress

WP_Image_Editor_Imagick::remove_pdf_alpha_channel()

Removes PDF alpha after it’s been read.

Source

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() );
		}
	}
}

Changelog

Version Description
6.4.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/remove_pdf_alpha_channel