7

I am using imageio with Python. It seems to have a cleaner API than PIL and consorts, so I would like to continue using imageio instead of other tools.

I know how to get image size:

height, width, channels = imageio.imread(filepath).shape

Is there a way to get the size of an image, without needing to load it fully to memory? This should be possible, isnt't it? At least for a number of formats that (I guess) have the image size in the header?

Zorglub29
  • 6,979
  • 6
  • 20
  • 37
  • Related: https://stackoverflow.com/questions/15800704/get-image-size-without-loading-image-into-memory/19035508 – sshashank124 May 20 '18 at 08:45
  • That is true, thank you for the link. I had not found it as it was not imageio related, but this is basically the same question I ask for imageio ;) – Zorglub29 May 20 '18 at 08:51
  • I couldn't find a solution for imageio specifically but since the link contains some non-library based solutions, hopefully they might be helpful – sshashank124 May 20 '18 at 08:52
  • 1
    Yes, I saw those. Ideally I would prefer to use only imageio, but if it does not have the features I look for I will use one of the other solutions mentioned there. I will wait a bit for other answers though. – Zorglub29 May 20 '18 at 08:56
  • 1
    future readers might be interested in `imageio`'s issue tracking this topic https://github.com/imageio/imageio/issues/362 – mostsquares Jun 15 '20 at 17:31
  • For future readers: This will become possible in ImageIO v3 (ETA fall 2022, but timeline may change) where it is a core part of the API: `iio.improps(filepath).shape` (you'll also get access to dtype and other commonly available metadata). You can get early access to this feature for formats supported by pillow once [this PR](https://github.com/imageio/imageio/pull/739) is merged. Other formats (e.g., video) will follow. – FirefoxMetzger Feb 08 '22 at 18:35

0 Answers0