mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-16 02:04:45 +03:00
Check for scaling in macOS windows
This commit is contained in:
parent
7eaac3fcf0
commit
79914ec8a5
|
@ -45,8 +45,7 @@ def grab(
|
||||||
args = ["screencapture"]
|
args = ["screencapture"]
|
||||||
if window:
|
if window:
|
||||||
args += ["-l", str(window)]
|
args += ["-l", str(window)]
|
||||||
# -R is not working with -l
|
elif bbox:
|
||||||
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])
|
||||||
|
@ -54,9 +53,29 @@ def grab(
|
||||||
im.load()
|
im.load()
|
||||||
os.unlink(filepath)
|
os.unlink(filepath)
|
||||||
if bbox:
|
if bbox:
|
||||||
# manual crop for windowed mode
|
|
||||||
if window:
|
if window:
|
||||||
im_cropped = im.crop(bbox)
|
# Determine if the window was in retina mode or not
|
||||||
|
# by capturing it without the shadow,
|
||||||
|
# and checking how different the width is
|
||||||
|
fh, filepath = tempfile.mkstemp(".png")
|
||||||
|
os.close(fh)
|
||||||
|
subprocess.call(
|
||||||
|
["screencapture", "-l", str(window), "-o", "-x", filepath]
|
||||||
|
)
|
||||||
|
with Image.open(filepath) as im_no_shadow:
|
||||||
|
retina = im.width - im_no_shadow.width > 100
|
||||||
|
os.unlink(filepath)
|
||||||
|
|
||||||
|
# Since screencapture's -R does not work with -l,
|
||||||
|
# crop the image manually
|
||||||
|
if retina:
|
||||||
|
left, top, right, bottom = bbox
|
||||||
|
im_cropped = im.resize(
|
||||||
|
(right - left, bottom - top),
|
||||||
|
box=tuple(coord * 2 for coord in bbox),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
im_cropped = im.crop(bbox)
|
||||||
im.close()
|
im.close()
|
||||||
return im_cropped
|
return im_cropped
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user