Preserve layered text when saving images #2198
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks for using PyMuPDF to start with. Of course the result quality will depend on the DPI you choose for the pixmap. bbox = page.get_image_rects(xref)[0] # delivers list, because one image maybe displayed multiple times
pix = page.get_pixmap(dpi=150, clip=bbox)
pix.save("interesting.png") |
Beta Was this translation helpful? Give feedback.
Thanks for using PyMuPDF to start with.
The easiest way to achieve your goal surprisingly (maybe) is to not extract the image, but to make a "photo" from the area where the image is visible - and save this as an image.
Step 1: Identify the image
Step 2: Compute the area where displayed by the page
Step 3: Make a Pixmap from that area. This will contain everything visible: the image and possible other stuff.
Step 4: Save the Pixmap as an image file.
Of course the result quality will depend on the DPI you choose for the pixmap.
Here is a snippet. I am assuming you have the xref of the image of interest: