mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-10 16:22:22 +03:00
feat(ImageGrab): enhance grab function to support window-based screenshot capturing on macOS
This commit is contained in:
parent
dc9e0cf326
commit
d6dcd803c7
|
@ -43,7 +43,10 @@ def grab(
|
||||||
fh, filepath = tempfile.mkstemp(".png")
|
fh, filepath = tempfile.mkstemp(".png")
|
||||||
os.close(fh)
|
os.close(fh)
|
||||||
args = ["screencapture"]
|
args = ["screencapture"]
|
||||||
if bbox:
|
if window:
|
||||||
|
args += ["-l", str(window)]
|
||||||
|
# -R is not working with -l
|
||||||
|
if bbox and not window:
|
||||||
left, top, right, bottom = bbox
|
left, top, right, bottom = bbox
|
||||||
args += ["-R", f"{left},{top},{right-left},{bottom-top}"]
|
args += ["-R", f"{left},{top},{right-left},{bottom-top}"]
|
||||||
subprocess.call(args + ["-x", filepath])
|
subprocess.call(args + ["-x", filepath])
|
||||||
|
@ -51,9 +54,16 @@ def grab(
|
||||||
im.load()
|
im.load()
|
||||||
os.unlink(filepath)
|
os.unlink(filepath)
|
||||||
if bbox:
|
if bbox:
|
||||||
im_resized = im.resize((right - left, bottom - top))
|
# manual crop for windowed mode
|
||||||
im.close()
|
if window:
|
||||||
return im_resized
|
left, top, right, bottom = bbox
|
||||||
|
im_cropped = im.crop((left, top, right, bottom))
|
||||||
|
im.close()
|
||||||
|
return im_cropped
|
||||||
|
else:
|
||||||
|
im_resized = im.resize((right - left, bottom - top))
|
||||||
|
im.close()
|
||||||
|
return im_resized
|
||||||
return im
|
return im
|
||||||
elif sys.platform == "win32":
|
elif sys.platform == "win32":
|
||||||
if window is not None:
|
if window is not None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user