Extract an API to predict the DPI used by img2pdf (with Pillow) #200

Open
mara0004 wants to merge 1 commit from mara0004/img2pdf:dpi_predictor into main
Contributor

When embedding img2pdf in a processing pipeline, it may be desired to predict the output size without actually converting the image, to defer any heavy processing to the export layer.

img2pdf applies some adjustments to the DPI provided by Pillow, so factor these out into a separate function that can be used by the embedder to calculate output size.

When embedding img2pdf in a processing pipeline, it may be desired to predict the output size without actually converting the image, to defer any heavy processing to the export layer. img2pdf applies some adjustments to the DPI provided by Pillow, so factor these out into a separate function that can be used by the embedder to calculate output size.
mara0004 added 1 commit 2024-08-25 15:22:51 +00:00
Author
Contributor

A possible issue I see with this is that it only covers the Pillow part, i.e. not the custom MIFF and JP2 parsers.

Pillow should be able to handle JP2 these days (at least current Linux wheels do), and I'm not too interested in MIFF, so this would already be helpful to me.

Yet, it might seem preferable to have a DPI function that could cover all code paths, but I'm not sure that's feasible, as the MIFF and JP2 DPI seem to be buried rather deeply in the control flow, or tied to other work.
And this would need a more complex API design than for just a Pillow image that can be seek()'ed by the caller...

A possible issue I see with this is that it only covers the Pillow part, i.e. not the custom MIFF and JP2 parsers. Pillow should be able to handle JP2 these days (at least current Linux wheels do), and I'm not too interested in MIFF, so this would already be helpful to me. Yet, it might seem preferable to have a DPI function that could cover all code paths, but I'm not sure that's feasible, as the MIFF and JP2 DPI seem to be buried rather deeply in the control flow, or tied to other work. And this would need a more complex API design than for just a Pillow image that can be seek()'ed by the caller...
Owner

This change looks okay. Did you run the testsuite for your pull requests?

This change looks okay. Did you run the testsuite for your pull requests?
Author
Contributor

Thanks. Yes, I did run the test suite.

The thing is, on my distro (Fedora 37), 10 tests are already failing on unaltered main.
This patch does not change the number of failing tests, but perhaps you had better confirm this did not break anything by running tests yourself, assuming there aren't any test suite issues on your end.

Thanks. Yes, I did run the test suite. The thing is, on my distro (Fedora 37), 10 tests are already failing on unaltered main. This patch does not change the number of failing tests, but perhaps you had better confirm this did not break anything by running tests yourself, assuming there aren't any test suite issues on your end.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u dpi_predictor:mara0004-dpi_predictor
git checkout mara0004-dpi_predictor

Merge

Merge the changes and update on Forgejo.
git checkout main
git merge --no-ff mara0004-dpi_predictor
git checkout main
git merge --ff-only mara0004-dpi_predictor
git checkout mara0004-dpi_predictor
git rebase main
git checkout main
git merge --no-ff mara0004-dpi_predictor
git checkout main
git merge --squash mara0004-dpi_predictor
git checkout main
git merge --ff-only mara0004-dpi_predictor
git checkout main
git merge mara0004-dpi_predictor
git push origin main
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: josch/img2pdf#200
No description provided.