Skip to content

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

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()

Activity

  1. NewUserHa commented on Jan 5, 2022

    @NewUserHa
    Author

    .save throw the same error as well.

  2. changed the title [-]size 0,0 image use .tobytes() throw `SystemError: tile cannot extend outside image`[/-] [+]size 0,0 image use `.save()`/`.tobytes()` throw `SystemError: tile cannot extend outside image`[/+] on Jan 5, 2022
  3. radarhere commented on Jan 5, 2022

    @radarhere
    Member

    Just to be clear, what format are trying to save the image as?

  4. NewUserHa commented on Jan 5, 2022

    @NewUserHa
    Author

    the .save is .jpg

  5. radarhere commented on Jan 7, 2022

    @radarhere
    Member

    When I try and save a (0, 0) JPEG, if I push past the Pillow error, I get "Empty JPEG image (DNL not supported)" which is coming from libjpeg itself - https://github.com/freedesktop/libjpeg/blob/b4f886fcbb692e20fb4da4e6e3ead57f79444734/jcmaster.c#L54-L57. So it doesn't look like it is possible to create a (0, 0) JPEG file.

    I've created PR #5938 to fix the error coming from tobytes().

  6. NewUserHa commented on Jan 7, 2022

    @NewUserHa
    Author

    I searched a few minutes, it seems like .jpg, .png don't support size 0x0 image. but no info for .tiff and other formats.

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