Support » Plugin: PDF Thumbnails » Black areas on thumbnails

  • Hi – the plugin works fine, however on some PDFs it creates black areas all over the image (https://i.imgur.com/fKBncKw.jpg). I browsed through these threads and it seems the problem is transparency used in the PDF files – can anything be done about it?

    I’ve been trying to play around the pdf_thumbnail_generate_image_blob action but to no avail. Any ideas on how to modify it to get rid of the black?

    Here’s what I’ve tried:

    add_action('pdf_thumbnails_generate_image_blob', function ($blob, $filename) {
    
        $imagick = new Imagick();
        $imagick->readImage($filename);
        $imagick->setIteratorIndex(0);
        $imagick->setCompression(Imagick::COMPRESSION_JPEG);
        $imagick->setCompressionQuality(100);
        $imagick->setImageBackgroundColor('#ffffff');
        $imagick->flattenImages();
        $imagick->setImageFormat('jpg');
        return $imagick->getImageBlob();
    
    }, 10, 2);

    I also noticed that for some thumbnails the black areas appear only in the WordPress-resized sizes of thumbnail and “full” size looks fine. For others, this issue is happening for all sizes.

    I tried to convert some of them via the command line to check – and the results were similar – some of them converted fine (the ones that appeared fine in “full” size), others converted with the black areas (and were also bugged in “full” size in WP).

    • This topic was modified 2 years, 3 months ago by  Justyna Ratajczak. Reason: additional information
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author stianlik

    (@stianlik)

    I haven’t tested this, but you may be able to disable the alpha channel using setImageAlphaChannel with imagick::ALPHACHANNEL_DEACTIVATE. Also, see related StackOverflow answer.

    • This reply was modified 2 years, 3 months ago by  stianlik.

    Just tested it – adding $imagick->setImageAlphaChannel(self::ALPHACHANNEL_DEACTIVATE); to the function caused “HTTP error” when uploading the PDF into WordPress, and didn’t generate a thumbnail at all. Used it like this:

    add_action('pdf_thumbnails_generate_image_blob', function ($blob, $filename) {
    
        $imagick = new Imagick();
        $imagick->readImage($filename);
        $imagick->setImageAlphaChannel(self::ALPHACHANNEL_DEACTIVATE);
        $imagick->setIteratorIndex(0);
        $imagick->setImageFormat('jpg');
        return $imagick->getImageBlob();
    
    }, 10, 2);

    Also tried setting $imagick->setImageAlphaChannel(11); as per the answer you linked – no HTTP error but still black areas on the generated thumbnails.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Black areas on thumbnails’ is closed to new replies.