Reading image dimensions before it is loaded from a web form using python.

Norman Khine norman at khine.net
Sat Jun 30 20:20:17 CEST 2007


Hello,
I am writing an application using python that allows the user to upload
an image to a folder on the server.

Is there a way to get the size of the file before it has been uploaded
onto the server and give an error if the size does not comply to the
maximum size.

So far, my apps loads the image and checks it and then returns an error
if the image is too big.  Which is a bit pointless in that I should be
able to get the file info before it is loaded, but I am not sure where
to go.

PIL reads the image size before it is loaded, but this is when I run
this on my local machine. There is also a post
http://mail.python.org/pipermail/python-list/2005-May/323018.html by
Will McGugan where he loads 1px and rejects it if its too big. But his
apps is an image scraper, so I suppose it fits his use case where he
checks the size and then pulls the image if it fits.

Anyone with ideas on how to deal with this.

Thanks

Norman




More information about the Python-list mailing list