Search code examples
imagewxpythoncorrupt

wxpython display a corupted image


Does anyone out there have a process or solution for displaying a corrupted image using wxpython. To be clear the image is corrupted but ACDSEE is still able to display it (all be it displayed corrupted), also the default windows fax/image viewer can display the image (all be it corrupted). When I try to process the image with wx I get an error and my script stops:

    image.thumbnail((NewWidth, temp_height), Image.ANTIALIAS)
  File "C:\Python27\lib\site-packages\PIL\Image.py", line 1559, in thumbnail
    self.load()
  File "C:\Python27\lib\site-packages\PIL\ImageFile.py", line 215, in load
    raise_ioerror(e)
  File "C:\Python27\lib\site-packages\PIL\ImageFile.py", line 52, in raise_ioerror
    raise IOError(message + " when reading image file")
IOError: broken data stream when reading image file

I realize that I could just find where the error occurs and "skip" any corrupted images but I would rather be able to display them (than skip them) despite the corruption, as the two programs I mention above can. Any help/suggestions/guidance would be appreciated.

FYI. Not downing wx, I LOVE it! Ms Paint cannot display the image, it gracefully fails and gives a message that the image is corrupted (the equivalent of skipping) and MS Picture Manager actually hung on the image. So if the consensus is that wx just can't handle corrupted images I am willing to accept that and will add "skipping" code for corrupted images, but I wanted to ask the question before I did so.


Solution

  • I don't think wxPython supports this currently. I would just create some kind of default broken image or message that you can display instead. You might also try using the Python Imaging Library itself to open the image.

    If you can find an open source image viewer that does work with corrupt images, than you should take a look at their code to see if we could patch wxPython.