Skip to content

Imagecropping fails on NamedImage (PIL ValueError: embedded null byte) #108

Open
@mtrebron

Description

@mtrebron

Traceback:

Traceback (most recent call last):
  File "/usr/local/Plone52/buildout-cache/eggs/plone.namedfile-5.5.1-py3.9.egg/plone/namedfile/scaling.py", line 249, in __call__
    result = self.create_scale(
  File "/usr/local/Plone52/buildout-cache/eggs/plone.app.imagecropping-2.2.2-py3.9.egg/plone/app/imagecropping/dx.py", line 42, in create_scale
    data = self._crop(data, self.box)
  File "/usr/local/Plone52/buildout-cache/eggs/plone.app.imagecropping-2.2.2-py3.9.egg/plone/app/imagecropping/dx.py", line 31, in _crop
    image = PIL.Image.open(data)
  File "/usr/local/Plone52/buildout-cache/eggs/Pillow-6.2.2-py3.9-linux-x86_64.egg/PIL/Image.py", line 2766, in open
    fp = builtins.open(filename, "rb")
ValueError: embedded null byte

I worked around the issue by patching https://github.com/collective/plone.app.imagecropping/blob/master/src/plone/app/imagecropping/dx.py#L31

from ZODB.blob import BlobFile

def _crop(self, data, box, default_format='PNG'):
        """crop data (image as open file) to box
        """
        # Force NamedImage data to be a BytesIO object
        if not isinstance(data, BlobFile):
            data = BytesIO(data)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions