Skip to content

ENH: add width, height, and data_size properties to ImageFile#3881

Open
itisar-345 wants to merge 9 commits into
py-pdf:mainfrom
itisar-345:enh-image-issue-3822
Open

ENH: add width, height, and data_size properties to ImageFile#3881
itisar-345 wants to merge 9 commits into
py-pdf:mainfrom
itisar-345:enh-image-issue-3822

Conversation

@itisar-345

Copy link
Copy Markdown

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:

  • .width : image width in pixels, read from the stream's /Width
  • .height : image height in pixels, read from the stream's /Height
  • .data_size : compressed byte size of the stream, read from the raw stream bytes (no decompression)

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.

@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.87%. Comparing base (efc511b) to head (d7a5808).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3881   +/-   ##
=======================================
  Coverage   97.86%   97.87%           
=======================================
  Files          57       57           
  Lines       10738    10761   +23     
  Branches     2006     2011    +5     
=======================================
+ Hits        10509    10532   +23     
  Misses        127      127           
  Partials      102      102           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stefan6419846 stefan6419846 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I have added some remarks to the proposed changes.

Comment thread docs/modules/PageObject.rst
Comment thread pypdf/_page.py
Comment thread pypdf/_page.py
Comment thread pypdf/_page.py
Comment thread pypdf/_page.py
Comment thread pypdf/_page.py
Comment thread pypdf/_page.py
Comment thread pypdf/_page.py
Comment thread tests/test_images.py
Comment thread tests/test_images.py
@itisar-345
itisar-345 requested a review from stefan6419846 June 25, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants