mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-10 16:22:22 +03:00
Merge 6ed5b2abdd
into 329d6a6a62
This commit is contained in:
commit
0813e681b9
|
@ -42,9 +42,9 @@ or the clipboard to a PIL image memory.
|
|||
.. versionadded:: 7.1.0
|
||||
|
||||
:param window:
|
||||
HWND, to capture a single window. Windows only.
|
||||
Capture a single window. On Windows, this is a HWND. On macOS, it uses windowid.
|
||||
|
||||
.. versionadded:: 11.2.1
|
||||
.. versionadded:: 11.2.1 (Windows), 12.0.0 (macOS)
|
||||
:return: An image
|
||||
|
||||
.. py:function:: grabclipboard()
|
||||
|
|
|
@ -43,7 +43,10 @@ def grab(
|
|||
fh, filepath = tempfile.mkstemp(".png")
|
||||
os.close(fh)
|
||||
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
|
||||
args += ["-R", f"{left},{top},{right-left},{bottom-top}"]
|
||||
subprocess.call(args + ["-x", filepath])
|
||||
|
@ -51,6 +54,12 @@ def grab(
|
|||
im.load()
|
||||
os.unlink(filepath)
|
||||
if bbox:
|
||||
# manual crop for windowed mode
|
||||
if window:
|
||||
im_cropped = im.crop(bbox)
|
||||
im.close()
|
||||
return im_cropped
|
||||
else:
|
||||
im_resized = im.resize((right - left, bottom - top))
|
||||
im.close()
|
||||
return im_resized
|
||||
|
|
Loading…
Reference in New Issue
Block a user