Skip to content

How to reduce the size of an image #1335

Answered by JorjMcKie
alSeveR asked this question in Q&A
Discussion options

You must be logged in to vote

If you insert the same image on multiple pages the logic automatically determines this and reuses the already embedded image.
It is however much faster to avoid the effort detecting this and use this kind of loop:

xref = 0  # xref start value
for page in doc:
    xref = page.insert_image(rect, ..., xref=xref)  # will pick up any previously returned xref > 0

This is how to scale down continuously:

At the end, do not forget to save the document with garbage>=3, deflate=True

Replies: 5 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@JorjMcKie
Comment options

Answer selected by JorjMcKie
Comment options

You must be logged in to vote
1 reply
@JorjMcKie
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1333 on October 22, 2021 13:33.