-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
RGBA image losing its transparency when saved as pdf #7312
Comments
I can't confirm JPEG2000. Your image is transparent after conversion. |
I'm also unable to replicate the problem with either format. Are you sure that you are using Pillow 10.0.0, and not a version before 9.5.0? |
I reinstalled it before to confirm the bug was on the latest version. Personally I checked all under windows with acrobat reader (black) sumatra (transparent) pdf.js( black and damaged) chrome (black) |
I am using Pillow 10.0.0 and getting the same incorrect results using the code above: |
How did you install Pillow? What version of OpenJPEG are you using? >>> from PIL import features
>>> features.version_codec("jpg_2000")
'2.5.0' |
I have installed it using pip on Windows 11. The OpenJPEG version is 2.5.0. |
Sorry, people, could you be a bit more verbose here? You are claiming that the initial problem is related to both PDF and JP2K. So could we isolate this? For example, if you are sure that the problem with PDF happens because of embedding bad JP2K, let's focus on the JP2K problem here. Otherwise, if there are separate problems, let's consider them separate. I've tried to convert the example image to JP2K above and experienced no problems, it has transparency. If some of you have different results, could you please at least mention this and provide your result with broken transparency and expose why you think it s broken (software you are using to viewing, for example). |
The problem is not (only) related to JP2K, because in my example you find 2 transparent png images, both are not correctly converted to PDF. The PDF files have been opened with:
|
"is not related to JP2K" and "is not only related to JP2K" are two completely different statements. @pubpub-zz could you provide any example or proof that you are experiencing problems with JP2K? |
The file opened in the right window on my screenshot is your PDF from the comment which claimed as generated using Pillow 10.0. |
My test showed that the viewer allows to show or not the transparency. I have the same feeling about jpeg 2000 viewer (the image was not good with nomacs but displayed correctly in gimp and imagemagick) digging further in the pdf specification I found this: I've removed ColorSpace to take into account There is still a color inversion but I think this is a bug in pdf.js(mozilla/pdf.js#16782) to sum-up, can you :
with the fixed PDF: |
I've created PR #7316 to set SMaskInData to 1.
Could you explain this some more?
What makes you think that the color inversion is a bug in pdf.js, but not the BitsPerComponent problem? Does "allow the extraction of data from the image" mean something special, or is that just another way of saying "appear correctly in a viewer"? |
👍
This is an extract from Pdf 1.7 reference: For the same reason we should ignore BitsPerComponents
I've tested a few set of PdfViewer( Acrobat / Sumatra / pdf.js / chrome) and the issue was observable in PDF.js. previously this time of error was linked with Decode entry but setting the Decode entry was not improving that. |
Thanks. I've updated the PR to remove those properties. I presume that is sufficient to fix the original problem here. 'Transparent_Image2' is also an RGBA image, so I think it should fix that as well. |
'Transparent_Image' is different, because it is not RGBA, but P. I've created PR #7323. With it, running from PIL import Image
img = Image.open("transparent_image.png")
img.save("transparent_image.pdf") gives This should clearly be an improvement, because the background is no longer green, but @mnmtz, let us know if you think that is fixed. If that is all good, then everything in this issue should be resolved. |
As for me, it looks like that the PR is doing the trick. Thank you! |
What did you do?
convert an png to image to pdf or
JPEG2000edit:
after checking with various image viewer, I've observed that the issue could be linked with my original viewer(nomacs)
In order to not bother any I will left on side JPEG2000 and carry on my investigations
What did you expect to happen?
have the good alpha channel
What actually happened?
alpha channel not correctly displayed in pdf
is not the good oneWhat are your OS, Python and Pillow versions?
with this png
output
mode : RGBA
mode jp2 : RGBA
but the image in the PDF has lost its transparency
same for the jpeg2000 image, although still reported as RGBAThe text was updated successfully, but these errors were encountered: