WP_Image_Editor_Imagick::remove_pdf_alpha_channel()

In this article

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

VersionDescription
6.4.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.