Skip to content

Image of size zero is not getting initialized #2259

Description

@rakeshvar

I want an image with zero size. I have a lot of use for it.

>>> from PIL import Image as im
>>> import numpy as np
>>> im.fromarray(np.empty((0, 0), dtype=np.uint8))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/PIL/Image.py", line 2187, in fromarray
    return frombuffer(mode, size, obj, "raw", rawmode, 0, 1)
  File "/usr/local/lib/python3.4/dist-packages/PIL/Image.py", line 2114, in frombuffer
    _check_size(size)
  File "/usr/local/lib/python3.4/dist-packages/PIL/Image.py", line 2001, in _check_size
    raise ValueError("Width and Height must be > 0")
ValueError: Width and Height must be > 0

This was working previously. But after this commit, in the latest version (i.e. 3.4.2) it is throwing an error.

As @manthey points out in the commit, one can create a zero sized image by cropping an existing one. So this too should be allowed.

Thanks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions