mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-10-28 14:41:07 +03:00
Do not resize macOS retina screenshots by default
This commit is contained in:
parent
76f04b46c5
commit
0a272ccc7f
|
|
@ -25,8 +25,15 @@ class TestImageGrab:
|
||||||
ImageGrab.grab(include_layered_windows=True)
|
ImageGrab.grab(include_layered_windows=True)
|
||||||
ImageGrab.grab(all_screens=True)
|
ImageGrab.grab(all_screens=True)
|
||||||
|
|
||||||
im = ImageGrab.grab(bbox=(10, 20, 50, 80))
|
if sys.platform == "darwin":
|
||||||
assert im.size == (40, 60)
|
im = ImageGrab.grab(bbox=(10, 20, 50, 80))
|
||||||
|
assert im.size in ((40, 60), (80, 120))
|
||||||
|
|
||||||
|
im = ImageGrab.grab(bbox=(10, 20, 50, 80), scale_down=True)
|
||||||
|
assert im.size == (40, 60)
|
||||||
|
else:
|
||||||
|
im = ImageGrab.grab(bbox=(10, 20, 50, 80))
|
||||||
|
assert im.size == (40, 60)
|
||||||
|
|
||||||
@skip_unless_feature("xcb")
|
@skip_unless_feature("xcb")
|
||||||
def test_grab_x11(self) -> None:
|
def test_grab_x11(self) -> None:
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,14 @@ or the clipboard to a PIL image memory.
|
||||||
|
|
||||||
.. versionadded:: 1.1.3
|
.. versionadded:: 1.1.3
|
||||||
|
|
||||||
.. py:function:: grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=None, window=None)
|
.. py:function:: grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=None, window=None, scale_down=False)
|
||||||
|
|
||||||
Take a snapshot of the screen. The pixels inside the bounding box are returned as
|
Take a snapshot of the screen. The pixels inside the bounding box are returned as
|
||||||
an "RGBA" on macOS, or an "RGB" image otherwise. If the bounding box is omitted,
|
"RGBA" on macOS, or "RGB" image otherwise. If the bounding box is omitted,
|
||||||
the entire screen is copied, and on macOS, it will be at 2x if on a Retina screen.
|
the entire screen is copied.
|
||||||
|
|
||||||
|
On macOS, it will be at 2x if on a Retina screen. If this is not desired, pass
|
||||||
|
``scale_down=True``.
|
||||||
|
|
||||||
On Linux, if ``xdisplay`` is ``None`` and the default X11 display does not return
|
On Linux, if ``xdisplay`` is ``None`` and the default X11 display does not return
|
||||||
a snapshot of the screen, ``gnome-screenshot``, ``grim`` or ``spectacle`` will be
|
a snapshot of the screen, ``gnome-screenshot``, ``grim`` or ``spectacle`` will be
|
||||||
|
|
@ -25,8 +28,8 @@ or the clipboard to a PIL image memory.
|
||||||
.. versionadded:: 7.1.0 Linux support
|
.. versionadded:: 7.1.0 Linux support
|
||||||
|
|
||||||
:param bbox: What region to copy. Default is the entire screen.
|
:param bbox: What region to copy. Default is the entire screen.
|
||||||
On macOS, this is not increased to 2x for Retina screens, so the full
|
On macOS, this is increased to 2x for Retina screens, so the full
|
||||||
width of a Retina screen would be 1440, not 2880.
|
width of a Retina screen would be 2880, not 1440.
|
||||||
On Windows, the top-left point may be negative if ``all_screens=True``
|
On Windows, the top-left point may be negative if ``all_screens=True``
|
||||||
is used.
|
is used.
|
||||||
:param include_layered_windows: Includes layered windows. Windows OS only.
|
:param include_layered_windows: Includes layered windows. Windows OS only.
|
||||||
|
|
@ -47,6 +50,11 @@ or the clipboard to a PIL image memory.
|
||||||
HWND, to capture a single window. Windows only.
|
HWND, to capture a single window. Windows only.
|
||||||
|
|
||||||
.. versionadded:: 11.2.1
|
.. versionadded:: 11.2.1
|
||||||
|
|
||||||
|
:param scale_down: On macOS, Retina screens will provide images at 2x size by default. This will prevent that, and scale down to 1x.
|
||||||
|
Keyword-only argument.
|
||||||
|
|
||||||
|
.. versionadded:: 12.1.0
|
||||||
:return: An image
|
:return: An image
|
||||||
|
|
||||||
.. py:function:: grabclipboard()
|
.. py:function:: grabclipboard()
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ def grab(
|
||||||
all_screens: bool = False,
|
all_screens: bool = False,
|
||||||
xdisplay: str | None = None,
|
xdisplay: str | None = None,
|
||||||
window: int | ImageWin.HWND | None = None,
|
window: int | ImageWin.HWND | None = None,
|
||||||
|
*,
|
||||||
|
scale_down: bool = False,
|
||||||
) -> Image.Image:
|
) -> Image.Image:
|
||||||
im: Image.Image
|
im: Image.Image
|
||||||
if xdisplay is None:
|
if xdisplay is None:
|
||||||
|
|
@ -50,7 +52,7 @@ def grab(
|
||||||
im = Image.open(filepath)
|
im = Image.open(filepath)
|
||||||
im.load()
|
im.load()
|
||||||
os.unlink(filepath)
|
os.unlink(filepath)
|
||||||
if bbox:
|
if bbox and scale_down:
|
||||||
im_resized = im.resize((right - left, bottom - top))
|
im_resized = im.resize((right - left, bottom - top))
|
||||||
im.close()
|
im.close()
|
||||||
return im_resized
|
return im_resized
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user