Python PIL “IOError: image file truncated” with big images

前端 未结 5 1130
逝去的感伤
逝去的感伤 2020-12-02 06:17

I think this problem is not Zope-related. Nonetheless I\'ll explain what I\'m trying to do:

I\'m using a PUT_factory in Zope to upload images to the ZODB per FTP. Th

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 06:56

    Best thing is that you can:

    if img and img.meta_type == 'Image':
        pilImg = PIL.Image.open( StringIO(str(img.data)) )
    elif imgData:
        pilImg = PIL.Image.open( StringIO(imgData) )
    
    try:
        pilImg.load()
    except IOError:
        pass # You can always log it to logger
    
    pilImg.thumbnail((width, height), PIL.Image.ANTIALIAS)
    

    As dumb as it seems - it will work like a miracle. If your image has missing data, it will be filled with gray (check the bottom of your image).

    Note: usage of camel case in Python is discouraged and is used only in class names.

提交回复
热议问题