Skip to content

Instantly share code, notes, and snippets.

@willybahuaud
Created January 12, 2022 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willybahuaud/546cdaa74f912d49146fd51a1aff8aeb to your computer and use it in GitHub Desktop.
Save willybahuaud/546cdaa74f912d49146fd51a1aff8aeb to your computer and use it in GitHub Desktop.
avoir des arrières plans blancs sur les previews de PDF générés automatiquement
<?php
require_once ABSPATH . 'wp-includes/class-wp-image-editor.php';
require_once ABSPATH . 'wp-includes/class-wp-image-editor-imagick.php';
final class ExtendedWpImageEditorImagick extends \WP_Image_Editor_Imagick
{
protected function pdf_load_source()
{
$loaded = parent::pdf_load_source();
try {
$this->image->setImageAlphaChannel(\Imagick::ALPHACHANNEL_REMOVE);
$this->image->setBackgroundColor('white');
} catch (\Exception $exception) {
error_log($exception->getMessage());
}
return $loaded;
}
}
add_filter('wp_image_editors', function (array $editors) {
array_unshift($editors, ExtendedWpImageEditorImagick::class);
return $editors;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment