plone / plone.scale

Contains image scaling logic for use in Zope environments. It supports Zope 2, Pyramid and other systems build on using the Zope ToolKit (ZTK).
https://pypi.org/project/plone.scale
2 stars 15 forks source link

Damaged images fail on scale. #14

Closed jensens closed 3 months ago

jensens commented 8 years ago

Damaged images fail on scale, this info should somehow be shown to the user...

IOError: image file is truncated (56 bytes not processed)
  File "plone/buildout/eggs/plone.namedfile-4.1-py2.7.egg/plone/namedfile/scaling.py", line 220, in __call__
    **parameters
  File "plone/buildout/src-addons/plone.app.imagecropping/src/plone/app/imagecropping/dx.py", line 48, in create_scale
    **parameters
  File "plone/buildout/eggs/plone.namedfile-4.1-py2.7.egg/plone/namedfile/scaling.py", line 170, in create_scale
    **parameters
  File "plone/buildout/src/plone.scale/plone/scale/scale.py", line 51, in scaleImage
    image = scalePILImage(image, width, height, direction)
  File "plone/buildout/src/plone.scale/plone/scale/scale.py", line 164, in scalePILImage
    return _scale_thumbnail(image, width, height)
  File "plone/buildout/src/plone.scale/plone/scale/scale.py", line 98, in _scale_thumbnail
    image.thumbnail((width, height), PIL.Image.ANTIALIAS)
  File "PIL/Image.py", line 1800, in thumbnail
    im = self.resize(size, resample)
  File "PIL/Image.py", line 1533, in resize
    self.load()
  File "PIL/ImageFile.py", line 222, in load
    "(%d bytes not processed)" % len(b))
jensens commented 8 years ago

Btw., this is general, not image cropping related.

davisagli commented 3 months ago

There is a PIL setting we can use to let it make a best effort to load such images even if it detects they are truncated, instead of raising an error: https://pillow.readthedocs.io/en/stable/reference/ImageFile.html#PIL.ImageFile.LOAD_TRUNCATED_IMAGES

I think that's appropriate here. I would still like to see the part of the image that can be loaded (and in the case I'm looking at currently, it is not obviously broken).