I'm using VersatileImageField and everything was working fine until we meet a jpeg file.
This file can't be rendered by VersatileImageField and we understand that VersatileImageFiled uses Pillow itlself.
By the way we are trying to determine what kind of error exists with this image and maybe this can be the
error.
This code was tested and it worked fine with a lot of other images.
It should render a resized image
Returns the following error
The error says:
Django Version: 1.11
Exception Type: OSError
Exception Value: broken data stream when reading image file
Exception Location: C:..myenv\lib\site-packages\PIL\ImageFile.py in raise_ioerror, line 59
I trigger the error from:
<img src="{{ imagemodel.versatileimageproperty.crop.255x255 }}" srcset="{{ imagemodel.versatileimageproperty.crop.255x255 }} 1x, {{ imagemodel.versatileimageproperty.crop.255x255 }} 2x" alt="">
I was wondering if I can use the verify method to test if this image is truncated, avoid the yellow error page and show a message.
from PIL import Image
im = Image.open("C:\\absolutepathtoimage\\_DSC1318.jpg")
im.verify()
But verify returns nothing, no errors.
Image.verify is only implemented for PNG images, and it only verifies the CRC checksum in the image.
The only way to check from within Pillow is to load the image in a try/except and check the error. If you need as much info as possible from the image, you can set ImageFile.LOAD_TRUNCATED_IMAGES=True and it will attempt to parse as much as possible.