Skip to content

Commit

Permalink
Support saving screenshot of region, closes asweigart#116
Browse files Browse the repository at this point in the history
  • Loading branch information
ProditorMagnus authored May 17, 2024
1 parent eeca245 commit 78e6cd2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pyscreeze/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,17 +597,18 @@ def _screenshot_linux(imageFilename=None, region=None):
# need to save an image file to disk.
im = ImageGrab.grab() # use Pillow's grab() for Pillow 9.2.0 and later.

if imageFilename is not None:
im.save(imageFilename)

if region is None:
# Return the full screenshot.
if imageFilename is not None:
im.save(imageFilename)
return im
else:
# Return just a region of the screenshot.
assert len(region) == 4, 'region argument must be a tuple of four ints' # TODO fix this
region = [int(x) for x in region]
im = im.crop((region[0], region[1], region[2] + region[0], region[3] + region[1]))
if imageFilename is not None:
im.save(imageFilename)
return im
elif RUNNING_X11 and SCROT_EXISTS: # scrot only runs on X11, not on Wayland.
# Even if gnome-screenshot exists, use scrot on X11 because gnome-screenshot
Expand Down

0 comments on commit 78e6cd2

Please sign in to comment.