Transparent PDF content is black

Created on 7 December 2022, almost 2 years ago
Updated 29 March 2024, 8 months ago

There is a Problem if the PDF contains transparent content.

With the current implementation in MediaPdfThumbnailmagickManager.pdf::generateImageFromPDF() the transparent content is rendered in Black (as .jpg).

In the added patch [#3] I rewrote a little part to make it work for me.

🐛 Bug report
Status

Fixed

Version

5.3

Component

Code

Created by

🇨🇭Switzerland sraLton

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States Dave Kopecek

    #3 worked for me.

  • 🇨🇦Canada teknocat

    The only problem I see with this patch is that it does away with the use of the Spatie PDF to Image library, which accounts for various other things and additional options during the process of generating thumbnails, including an allowance for generating thumbnails for remote images.

    It is advantageous to keep using the spatie pdf library, but there isn't an easy way to use that and composite it onto a white background outside of that library (I tried that). However, if it uses the PNG format then transparency is allowed and you don't get a white background. This introduces a different issue, in that the thumbnails might not look good against whatever background colour they are on, but that problem can be easily resolved with CSS.

    It's a very simple solution and, if desired, the settings form could be updated to allow the developer to choose the desired format for any given thumbnail format. However, that means you'd then have to make sure you set it consistently in all places.

    As such, I suggest simply changing it to use PNG format as a default and I will submit a merge request with that solution for people to try out.

  • @teknocat opened merge request.
  • 🇨🇦Canada teknocat

    While the PNG option worked fine on my local machine on macOS, I found I still got a black background on my web server. This could just be due to the version of ImageMagick, so if that's the case then the first patch on this issue is better and it could be expanded on later if needed.

  • Status changed to Needs work over 1 year ago
  • 🇨🇭Switzerland sraLton

    My patch is definitely not the solution, since the transparency shouldn't be white.
    Therefore changing the status again.

  • Status changed to Fixed about 1 year ago
  • 🇫🇷France sgostanyan

    Image format selection has been introduced in version 6 Usage in Media view mode

    Thanks for your report

  • Status changed to Fixed about 1 year ago
  • 🇨🇦Canada teknocat

    Image format selection doesn't solve the problem. I have PDFs that have transparent background, using JPEG format for thumbnails, they still have a black background. Perhaps it would be prudent to add a config option to specify a default background colour to use?

  • 🇨🇦Canada teknocat

    Oh wait I think that's just me being dumb. Should use PNG rather than JPEG to leave backgrounds transparent.

  • 🇮🇹Italy finex

    Hi, I confirm that PNG format works fine, it should be added the option to set the background color when using jpg format instead of using the black default color.

Production build 0.71.5 2024