Re: memoryError in FpxImageUploadPlugin.py

Alec Bennett <[email protected]>
Newsgroups gmane.comp.python.image
Message-ID <[email protected]>
> i only care about JPG/PNG/GIF...
> is there any way do a fileformat-whitelist?

Seems almost too obvious to mention, but you could do something like:

fname = "something.jpg"

image_extensions = (".jpg", ".png", ".gif")

extension = os.path.splitext(fname)[1].lower()

if extension in image_extensions:

    print "its an image!"

    do_some_stuff(fname)





2011/4/15 Gábor Farkas <[email protected]>

> hi,
>
> we have a python webserver that handles files uploaded by the users.
> some of those files cause a MemoryError in PIL.
> (unfortunately i do not have such a file). as you can see, it happens
> in the FpxImagPlugin:
> (pil 1.1.7)
>
>   im = Image.open(original)
>  File "/usr/local/lib/python2.6/site-packages/PIL/Image.py", line 1976, in
> open
>   return factory(fp, filename)
>  File "/usr/local/lib/python2.6/site-packages/PIL/ImageFile.py", line
> 91, in __init__
>   self._open()
>  File "/usr/local/lib/python2.6/site-packages/PIL/FpxImagePlugin.py",
> line 61, in _open
>   self.ole = OleFileIO(self.fp)
>  File "/usr/local/lib/python2.6/site-packages/PIL/OleFileIO.py", line
> 260, in __init__
>   self.open(filename)
>  File "/usr/local/lib/python2.6/site-packages/PIL/OleFileIO.py", line
> 289, in open
>   self.loadfat(header)
>  File "/usr/local/lib/python2.6/site-packages/PIL/OleFileIO.py", line
> 309, in loadfat
>   s = self.getsect(ix)
>  File "/usr/local/lib/python2.6/site-packages/PIL/OleFileIO.py", line
> 324, in getsect
>   self.fp.seek(512 + self.sectorsize * sect)
> MemoryError
>
> any ideas what might cause this?
>
> alternatively, is there a way to tell PIL to only try to handle a
> given list of file-types?
> for example, in my cases, i only care about JPG/PNG/GIF... so i do not need
> PIL
> to try to find out if the file is in other formats.. is there any way
> do a fileformat-whitelist?
>
> thanks,
> gabor
> _______________________________________________
> Image-SIG maillist  -  [email protected]
> http://mail.python.org/mailman/listinfo/image-sig
>

_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.