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

Feature request: avoid altering images passed to FPDF.image() if there is no need to #693

Closed
eroux opened this issue Feb 16, 2023 · 4 comments · Fixed by #706
Closed

Feature request: avoid altering images passed to FPDF.image() if there is no need to #693

eroux opened this issue Feb 16, 2023 · 4 comments · Fixed by #706

Comments

@eroux
Copy link

eroux commented Feb 16, 2023

(orignal title: "not parsing images when possible")

A feature I really love in img2pdf is the fact that it doesn't load and save the image if it doesn't need to. For our use case this means a huge performance gain and also in the tests I made, a gain in size of the PDF since re-compression doesn't always produce smaller pictures. See this function for instance to get the CCITT payload from a tiff file, so that it can then be copied directly without even having to look at it

@eroux eroux added the bug label Feb 16, 2023
@Lucas-C
Copy link
Member

Lucas-C commented Feb 16, 2023

Hi @eroux

I am sorry but I am not sure to fully understand your intent here:
is this a feature request? You would like fpdf2 to not alter the image passed to FPDF.image() if it does not need to?

(if you confirm that this your correct intent, we could rename this issue title accordingly)

This would be possible for JPEG images, and CCITT/TIFF images I guess, but some images like PNG cannot be embedded in their native format in a PDF document.

In terms of code, this would mean a refactoring in fpdf/image_parsing.py and fpdf/fpdf.py to not systematically convert images to PIL.Image instances. This may not play well with existing features such as oversized images detection & downscaling, but is in theory perfectly doable.

I don't personnally plan to work on this task, but you or other contributors are welcome to do so 😊

@eroux
Copy link
Author

eroux commented Feb 16, 2023

That's exactly the intent indeed

@Lucas-C Lucas-C changed the title not parsing images when possible Feature request: avoid altering images passed to FPDF.image() if there is no need to Feb 16, 2023
@Lucas-C
Copy link
Member

Lucas-C commented Feb 16, 2023

@allcontributors please add @eroux for ideas

@allcontributors
Copy link

@Lucas-C

I've put up a pull request to add @eroux! 🎉

@eroux eroux mentioned this issue Feb 22, 2023
5 tasks
eroux added a commit to eroux/fpdf2 that referenced this issue Feb 22, 2023
This was referenced Feb 22, 2023
Lucas-C added a commit that referenced this issue Feb 23, 2023
Co-authored-by: Lucas Cimon <925560+Lucas-C@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants