Do not catch OSError raised when loading image

This commit is contained in:
Andrew Murray 2023-05-11 20:08:10 +10:00 committed by Ondrej Baranovič
parent 3ec03c6720
commit 7e29efd518

View File

@ -66,10 +66,6 @@ def grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=N
msg = "Pillow was built without XCB support" msg = "Pillow was built without XCB support"
raise OSError(msg) raise OSError(msg)
size, data = Image.core.grabscreen_x11(xdisplay) size, data = Image.core.grabscreen_x11(xdisplay)
im = Image.frombytes("RGB", size, data, "raw", "BGRX", size[0] * 4, 1)
if bbox:
im = im.crop(bbox)
return im
except OSError: except OSError:
if ( if (
xdisplay is None xdisplay is None
@ -89,6 +85,11 @@ def grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=N
return im return im
else: else:
raise raise
else:
im = Image.frombytes("RGB", size, data, "raw", "BGRX", size[0] * 4, 1)
if bbox:
im = im.crop(bbox)
return im
def grabclipboard(): def grabclipboard():