ENH: add width, height, and data_size properties to ImageFile - #3881
ENH: add width, height, and data_size properties to ImageFile#3881itisar-345 wants to merge 13 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3881 +/- ##
=======================================
Coverage 97.87% 97.87%
=======================================
Files 57 57
Lines 10760 10781 +21
Branches 2014 2018 +4
=======================================
+ Hits 10531 10552 +21
Misses 127 127
Partials 102 102 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
stefan6419846
left a comment
There was a problem hiding this comment.
Thanks for the PR. I have added some remarks to the proposed changes.
stefan6419846
left a comment
There was a problem hiding this comment.
See inline comments.
Additionally, unlike the PR description seems to propose, this currently does not have any benefits regarding speed, as the actual image decoding still happens on load time?
To be precise about what this PR actually does: So the actual benefit is at the call site, not in pypdf's internal decode path: e.g. If actually deferring the eager decode of I've also pushed fixes for the other inline comments (dropped the redundant |
Previously, inspecting an image's dimensions or size required fully decoding it via .image or .data, even if the caller only wanted to
filter out images that are too large to process.
ImageFile now exposes:
All three are read directly from the PDF stream header/raw bytes and require no image decoding, so they remain cheap even for large or numerous images.
.data and .image continue to be populated eagerly as before; this change is purely additive and does not alter existing behavior.