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

Return an empty bytestring from tobytes() for an empty image #5938

Merged
merged 1 commit into from Jan 7, 2022

Conversation

radarhere
Copy link
Member

Resolves #5931

>>> from PIL import Image
>>> Image.new("RGB", (1, 2)).tobytes()
b'\x00\x00\x00\x00\x00\x00'
>>> Image.new("RGB", (1, 1)).tobytes()
b'\x00\x00\x00'

given this progression, you would expect

>>> Image.new("RGB", (1, 0)).tobytes()

to give

b''

However, instead it currently throws an error.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "PIL/Image.py", line 748, in tobytes
    e.setimage(self.im)
SystemError: tile cannot extend outside image

This PR returns an empty bytestring instead.

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 this pull request may close these issues.

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