Skip to content

size 0,0 image use .save()/.tobytes() throw SystemError: tile cannot extend outside image #5931

@NewUserHa

Description

@NewUserHa

What did you do?

Create a size (0,0) image instead of None, for convenient in coding,

x.width
x.height
# other stuffs
x.tobytes()

to get rid of

if x:
    x.width
    x.height
   # other stuffs
    x.tobytes()

What did you expect to happen?

Normal, probably return b''

What actually happened?

---------------------------------------------------------------------------
SystemError                               Traceback (most recent call last)
<ipython-input-0-d240cdef7328> in <module>
----> 1 Image.new("RGB",(0,0)).tobytes()

c:\program files\python38\lib\site-packages\PIL\Image.py in tobytes(self, encoder_name, *args)
    720         # unpack data
    721         e = _getencoder(self.mode, encoder_name, args)
--> 722         e.setimage(self.im)
    723
    724         bufsize = max(65536, self.size[0] * 4)  # see RawEncode.c

SystemError: tile cannot extend outside image

What are your OS, Python and Pillow versions?

  • OS: Win10 1803
  • Python: 3.8.10
  • Pillow: 9.0.0
from PIL import Image
Image.new("RGB",(0,0)).tobytes()

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