-
Notifications
You must be signed in to change notification settings - Fork 510
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
get_pixmap with alpha produce gray image for transparent white image #2593
Comments
This effect is caused by setting transparency to 50% for apparently all your drawings. |
Do you have suggestion for keeping the image white? I have tried
as alternative, but this is 50 times slower. EDIT: slightly faster method with numpy:
|
It also doesn't solve the problem or does it?
These instructions set 50% transparency for fill and stroke colors. Who did that and why ... who knows. Emptying these objects (i.e. setting them to empty dictionaries |
Yes it does. Here is code snippet:
Output:
Color is converted to white when image is saved. |
Well, that's some logic inside Pillow then. |
I read pillow documentation again and found the mistake. I chose wrong mode 'RGBA' for pillow, I should use ' RGBa' because the image is premultiplied alpha. Here is the correct code snippet:
This colorspace difference is not mentioned in get_pixmap reference, and tutorial also use 'RGBA' mode. Probably the documentation should be updated? |
Thanks for the hint! |
Please provide all mandatory information!
Describe the bug (mandatory)
I have a 50% transparent white image in pdf file. I want to use
Page.get_pixmap(alpha=True)
to render the page as pixmap, convert pixmap to pillow image, and paste it on another image (as watermark, for example). But the pixmap I get is gray image.To Reproduce (mandatory)
code snippet:
example pdf:
alpha.pdf
Expected behavior (optional)
white image with transparency
Your configuration (mandatory)
3.11.3 (main, Jun 5 2023, 09:32:32) [GCC 13.1.1 20230429]
linux
PyMuPDF 1.22.5: Python bindings for the MuPDF 1.22.2 library.
Version date: 2023-06-21 00:00:01.
Built for Python 3.11 on linux (64-bit).
PyMuPDF generated from source
Additional context (optional)
If I save pixmap with pix.save(), the saved image looks fine
The text was updated successfully, but these errors were encountered: