[wp-trac] [WordPress Trac] #45982: PDF thumbnails have a default black background
WordPress Trac
noreply at wordpress.org
Wed Sep 9 03:43:27 UTC 2020
#45982: PDF thumbnails have a default black background
--------------------------+------------------------------
Reporter: nebrekab | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 5.0.3
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by thatstevensguy):
Replying to [comment:8 joostdekeijzer]:
> With my patch (see comment above) and below code my pdf's are without
black backgrounds:
>
> {{{#!php
> <?php
> add_action( 'imagick_load_after_read', function( $image, $filename,
$file_extension ) {
> if ( 'pdf' === $file_extension ) {
> $image->setImageAlphaChannel( Imagick::ALPHACHANNEL_REMOVE );
> }
> }, 10, 3 );
>
> }}}
I am using a combination of this and above, I wish the hook was in core
already.
{{{#!php
<?php
/**
* Patch for black backgrounds on PDF's. Does require a core modification.
*
* https://core.trac.wordpress.org/ticket/45982
*
* /wp-includes/class-wp-image-editor-magick.php
*
* Line 166:
* do_action_ref_array( 'imagick_load_after_read', array( &$this->image,
$filename, $file_extension, $this->mime_type ) );
*
* @param object $image
* @param string $filename
* @param string $file_extension
* @param string $mime_type
*/
add_action('imagick_load_after_read', function (object $image, string
$filename, string $file_extension, string $mime_type) {
if ('pdf' === $file_extension) {
$image->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE);
$image->setImageBackgroundColor('#ffffff');
}
}, 10, 4);
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45982#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list