You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ValueError: Cannot save image with zero width or height (got size: (0, 50))
What actually happened?
GIF save:
ValueError: max() iterable argument is empty
(from GifImagePlugin.py line 959 in _get_optimize)
PNG save:
SystemError: tile cannot extend outside image
(from ImageFile.py line 682 in _encode_tile)
Context
I encountered this when using ImageGrab.grab(bbox=...) with programmatically-determined coordinates. When window detection returned invalid bounds (e.g., bbox=(50, 50, 50, 100) resulting in width=0), the save operation failed with these confusing errors.
What did you do?
Attempted to save an image with zero width or zero height.
What did you expect to happen?
A clear validation error like:
What actually happened?
GIF save:
(from
GifImagePlugin.pyline 959 in_get_optimize)PNG save:
(from
ImageFile.pyline 682 in_encode_tile)Context
I encountered this when using
ImageGrab.grab(bbox=...)with programmatically-determined coordinates. When window detection returned invalid bounds (e.g.,bbox=(50, 50, 50, 100)resulting in width=0), the save operation failed with these confusing errors.Note on existing issues
height and width must be > 0Suggested fix
Add dimension validation at the start of
Image.save():Environment