How to keep the original resolution of page images? #2631
-
Hello, I've been using How can I get pages as images in their originally scanned resolution? Please keep in mind that I have read similar discussion questions, but they were mainly about controlling the output resolution not keeping the input resolution. This is my code snippet:
Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Document pages in general have no "natural" resolution. You are talking about the (scanned) image from which the page was created, right? In [1]: import fitz
In [2]: doc = fitz.open("ocr-ed.pdf")
In [3]: page = doc[0]
In [4]: page.get_images()
Out[4]: [(12, 0, 1224, 1584, 8, 'DeviceRGB', '', 'R12', 'DCTDecode')]
In [5]: page.get_image_rects(12) # check if covering full page
Out[5]: [Rect(0.0, 0.0, 612.0, 792.0)]
In [6]: # true, so extract image to see its resolutions
In [7]: img = doc.extract_image(12)
In [8]: img["xres"], img["yres"]
Out[8]: (96, 96)
In [9]: # so you can render the page with dpi=96 |
Beta Was this translation helpful? Give feedback.
Document pages in general have no "natural" resolution. You are talking about the (scanned) image from which the page was created, right?
To find the scanned image's resolution, you must first locate it, then extract it to see the resolution values: