mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 10:26:19 +03:00
Merge pull request #6152 from radarhere/screencapture
Use screencapture arguments to crop on macOS
This commit is contained in:
commit
fa6e18a771
|
@ -30,14 +30,18 @@ def grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=N
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
fh, filepath = tempfile.mkstemp(".png")
|
fh, filepath = tempfile.mkstemp(".png")
|
||||||
os.close(fh)
|
os.close(fh)
|
||||||
subprocess.call(["screencapture", "-x", filepath])
|
args = ["screencapture"]
|
||||||
|
if bbox:
|
||||||
|
left, top, right, bottom = bbox
|
||||||
|
args += ["-R", f"{left},{right},{right-left},{bottom-top}"]
|
||||||
|
subprocess.call(args + ["-x", filepath])
|
||||||
im = Image.open(filepath)
|
im = Image.open(filepath)
|
||||||
im.load()
|
im.load()
|
||||||
os.unlink(filepath)
|
os.unlink(filepath)
|
||||||
if bbox:
|
if bbox:
|
||||||
im_cropped = im.crop(bbox)
|
im_resized = im.resize((right - left, bottom - top))
|
||||||
im.close()
|
im.close()
|
||||||
return im_cropped
|
return im_resized
|
||||||
return im
|
return im
|
||||||
elif sys.platform == "win32":
|
elif sys.platform == "win32":
|
||||||
offset, size, data = Image.core.grabscreen_win32(
|
offset, size, data = Image.core.grabscreen_win32(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user