Created
January 12, 2022 00:10
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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