Explanation
Loading images should be done lazily in the ImageFile class instead of on creating the ImageFile class. Relevant derivable values (width, height and data size) should be queried from the stream header without reading the actual stream to allow users to impose limits on which image streams should be loaded.
Code Example
from pypdf import PdfReader
reader = PdfReader("file.pdf")
for page in reader.pages:
for name in page.images.keys():
image = page.images[name]
if image.width > 5000 or image.data_size > 1_000_000:
continue
image.image.save(name)
Explanation
Loading images should be done lazily in the
ImageFileclass instead of on creating theImageFileclass. Relevant derivable values (width, height and data size) should be queried from the stream header without reading the actual stream to allow users to impose limits on which image streams should be loaded.Code Example