Extracted image is not transparant #1499
Unanswered
Gardener12
asked this question in
Looking for help
Replies: 2 comments 2 replies
-
If there is an smask > 0, then this xref contains the alpha channel (so to say) for the base image and you must make a composite pixmap of the both to recover the original image ... along this snippet: base = fitz.Pixmap(doc. xref)
mask = fitz.Pixmap/doc. smask)
pix = fitz.Pixmap(base, mask) |
Beta Was this translation helpful? Give feedback.
1 reply
-
A peculiarity of PDF is that it stores transparent images under separate xrefs. So one has to collect those pieces again for making the original. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, dear Github friends,
I have a question about PyMuPDF.
I have created a pdf (test.pdf) with only one transparent image in it (see 'original image.png').
When I extract the image with PyMuPDF, the result it's not transparant (see 'pic-11.png').
Also I notice, the original image has 32 bit depth, the extracted image has 24 bit depth.
What can be the cause/solution?
I'm new here on Github, so my apalogies for any mistakes I make here.
Thank you for your time!
p.s. I uploaded the python code as extract.txt, because otherwise the code was not displayed well.
p.s. I use Python 3.9 and MyMuPDF is updated
p.s. Whether I make the pdf in RGB modus or CMYK, the result is the same
--- the output about the image ---
{'number': 0, 'bbox': (36.0, 46.0, 173.25, 142.0), 'transform': (137.25, 0.0, -0.0, 96.0, 36.0, 46.0), 'width': 183, 'height': 128, 'colorspace': 1, 'cs-name': 'Indexed(1,DeviceRGB)', 'xres': 96, 'yres': 96, 'bpc': 8, 'size': 1641, 'digest': b'\xbf\xe52<\x96\xa8\x87x\xd7Y\xf4\xdc7fg\xaf', 'xref': 11}
{'ext': 'png', 'smask': 12, 'width': 183, 'height': 128, 'colorspace': 1, 'bpc': 8, 'xres': 96, 'yres': 96, 'cs-name': 'Indexed(1,DeviceRGB)', 'image': b'.....'}
test.pdf
extract.txt
Beta Was this translation helpful? Give feedback.
All reactions