pymupdf / PyMuPDF

PyMuPDF is a high performance Python library for data extraction, analysis, conversion & manipulation of PDF (and other) documents.
https://pymupdf.readthedocs.io
GNU Affero General Public License v3.0
4.56k stars 450 forks source link

Allow applying arbitrary transformations to images #3235

Open Rodrigodd opened 4 months ago

Rodrigodd commented 4 months ago

Is your feature request related to a problem? Please describe.

It is not currently supported to add an image with arbitrary transformation, which is needed when trying to rebuild a PDF from the data extracted from another PDF. See https://github.com/pymupdf/PyMuPDF/discussions/3230.

Describe the solution you'd like

Add a parameter morph to Page.insert_image, similar to the one found in the Shape API. This parameter could also be added to Page.show_pdf_page or to a new method like Shape.insert_image.

Describe alternatives you've considered

There is currently a workaround for this by abusing Page.show_pdf_page, see https://github.com/pymupdf/PyMuPDF/discussions/3230#discussioncomment-8709813.

Additional context

Page.get_image_info already returns a transform of the image, that could be used in the proposed morph parameter.

JorjMcKie commented 3 months ago

As mentioned in the Discussions section, I see no way to include this in our near to medium term planning. So I'm flagging this as "postpone" for now.