Open mikeboers opened 10 years ago
Code to do it with .png: http://stackoverflow.com/questions/8032642/how-to-obtain-image-size-using-standard-python-class-without-using-external-lib
You have to read only some file headers.
Also, PIL does not load the image to memory on .open
.
PIL doesn't require loading the image on .open
, but the docs don't lead me to believe that they never will. Looking at the SO question you linked to it seems that malformed JPEGs would result in loading everything, but I don't think that is something to be really concerned about.
So I guess we need to see how PIL[low] behaves with the other formats, and if it doesn't actually load the data (from valid files) then I'm cool with just using PIL to do it. Otherwise, it sounds like a good idea for another small library. ;)
This is underway now as it is required for the implementation of "retina" support for my personal site.
This is done in the "retina" branch.
It would be swell if we could predict the final width/height of an image so that they can be used in the template as well (to avoid a jump in layout when the images load).
Perhaps something like:
would render into:
Some testing needs to be done with regards to the speed at which dimension data can be extracted from images on disk without loading all of the data, so that we know if we can get away with the naive implementation or if we have to intelligently cache dimensions.