-
-
Notifications
You must be signed in to change notification settings - Fork 640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Grayscale PNGs render as a black box #349
Comments
This seems to be a reportlab issue/limitation, as they apparently do not like alpha channels for images at all (https://hg.reportlab.com/hg-public/reportlab/file/tip/src/reportlab/pdfbase/pdfdoc.py#l2050): _mode2CS={'RGB':'DeviceRGB', 'L':'DeviceGray', 'CMYK':'DeviceCMYK'} Thus, xhtml2pdf always creates RGB images for not support modes: xhtml2pdf/xhtml2pdf/xhtml2pdf_reportlab.py Lines 401 to 408 in f08ef9a
The only way I see for this is to convert the image to RGB yourself (replacing the alpha channel with a color of your choice) and thus completely avoid the default alpha channel handling of xhtml2pdf. I am not aware of any reliable way to automatically replace the background of an image as you have to be aware of the content for this to choose the correct color. |
@stefan6419846 Thanks a lot for taking a deeper look here! Do you think we need a special section in the docs for this problem? |
It might be worth documenting, although I am not sure where this would suit the best. Maybe by adding a dedicated FAQ page which can cover such aspects? |
RGB and Indexed PNGs work fine, but when I switch a working image to be Grayscale (in GIMP it's Image -> Mode -> Grayscale) the image shows up with the correct dimensions, but as a single black box every time.
There's no explicit error or anything like that. In fact, it would probably be better if there were an error saying there's no support because it would save people like me time from hunting down the problem.
Here's a data URL of the python logo that behaves the way I'm describing:
This is important because Grayscale images are usually smaller than their RGB equivalent, so they're useful for saving space and memory, especially when working with a large number of images.
The text was updated successfully, but these errors were encountered: