Skip to content

Inserting image with arbitrary tranformation #3230

Answered by Rodrigodd
Rodrigodd asked this question in Q&A
Discussion options

You must be logged in to vote

Unfortunately, the previous solution was not enough for me. The show_pdf_page was able to apply an arbitrary rotation followed by an arbitrary scaling, but I was at least hoping that it could apply the scaling before the rotation.

But I realize that I could chain two calls to show_pdf_page in order to achieve what I want. In fact, I could achieve any orientation-preserving transformation.

With a good dose of linear algebra (and try and error), I came up with the following function:

def add_tranformed_image(page, image_filename, transform):
    from math import tan, atan, sqrt, sin, cos

    # Because the Rect given to show_pdf_page cannot have negative width or
    # height, PyMuPDF canno…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@JorjMcKie
Comment options

@Rodrigodd
Comment options

@JorjMcKie
Comment options

@Rodrigodd
Comment options

@JorjMcKie
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Rodrigodd
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