From 78e6cd23c1fbd88bb86f5a33ec18b6bcd0a932ef Mon Sep 17 00:00:00 2001 From: Toom Date: Fri, 17 May 2024 20:15:13 +0300 Subject: [PATCH] Support saving screenshot of region, closes #116 --- pyscreeze/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyscreeze/__init__.py b/pyscreeze/__init__.py index a8dd81a..b1caf73 100644 --- a/pyscreeze/__init__.py +++ b/pyscreeze/__init__.py @@ -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