A faster way of getting image size from jpg files?

I think PIL is loading the images lazily (ref):

This is a lazy operation; this function identifies the file, but the file remains open and the actual image data is not read from the file until you try to process the data (or call the load() method).

PIL is probably identifying the image size from the jpeg header, avoiding the need to load the entire image. You could probably do the same thing via LibJpeg along the lines of this post: Get DCT coefficients of jpeg image - #5 by stevengj

1 Like