Skip to content
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 may cause large image size #25

Open
BrentHuang opened this issue Mar 18, 2024 · 2 comments
Open

get_pixmap may cause large image size #25

BrentHuang opened this issue Mar 18, 2024 · 2 comments

Comments

@BrentHuang
Copy link

doc = fitz.open(pdf_file)
for page in doc:
pix = page.get_pixmap()
img_file = f'{img_file_prefix}-{page.number}.jpg'
pix.save(img_file)

Will get_pixmap cause the generated JPG image to be too large in the above code? Is there a better way to convert every page in the PDF into a JPG image?

@JorjMcKie
Copy link
Collaborator

The pixmap size is directly linked to the page size.
Roughly width * height * 3 (for RGB images).
You can reduce this in a number of ways, e.g. using grayscale instead of RGB (reduce by factor 3), or by downscaling using a DPI value < 96.

@JorjMcKie
Copy link
Collaborator

When you save the JPEG you can also influence the quality - please see documentation.
A lower quality value also reduces the image size.
Also try PNG instead - it may compress better than JPG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants