Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
NewUserHa opened this issue Jan 4, 2022 · 5 comments · Fixed by #5938
Closed

Comments

@NewUserHa
Copy link

NewUserHa commented Jan 4, 2022

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()
@NewUserHa
Copy link
Author

.save throw the same error as well.

@NewUserHa NewUserHa 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 Jan 5, 2022
@radarhere
Copy link
Member

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

@NewUserHa
Copy link
Author

the .save is .jpg

@radarhere
Copy link
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().

@NewUserHa
Copy link
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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants