Repository navigation
Add scale option to ImageGrab.grab function #9253
Description
Activity
- changed the title
[-]add scale option to ImageGrab.grab function[/-][+]Add scale option to ImageGrab.grab function[/+]on Oct 14, 2025 Hi. What you're describing is documented at https://pillow.readthedocs.io/en/stable/reference/ImageGrab.html#PIL.ImageGrab.grab
If the bounding box is omitted, the entire screen is copied, and on macOS, it will be at 2x if on a Retina screen.
We've had discussions about this before - #7677 (comment)
If you consider this from the perspective of the rest of Pillow, such as
im.crop(box=...), I think it is more expected to have the rectangle co-ordinates produce an image that has dimensions(x2 - x1, y2 - y1).When discussing this in #6144, Apple's documentation was found to say
There are very few, if any, situations for which you need to use device coordinates directly.
I expect you're aware that you could just call
ImageGrab.grab()without abboxand thencrop()it yourself?
the resulted screenshot image has a low quality.
I'm not sure if by 'low quality' you simply mean that it is scaled down, or if you think that our resize operation doesn't scale an image down well. If you think that our resize operation produces a low quality result, that is a separate discussion to the ImageGrab functionality.
I expect you're aware that you could just call ImageGrab.grab() without a bbox and then crop() it yourself?
I know that this works. But it wastes resources to do the whole screen capture.
I'm not sure if by 'low quality' you simply mean that it is scaled down, or if you think that our resize operation doesn't scale an image down well. If you think that our resize operation produces a low quality result, that is a separate discussion to the ImageGrab functionality.
'low quality' means a low resolution. For example, I pass a bbox (0, 0, 100, 100).
ImageGrab.grabwith this bbox would produce a 200x200 image on Retina display. Butresizefunction reduces the image resolution to 100x100. The point is thatImageGrab.grabcallsscreencaptureto produce what I want. But it converts it into some unwanted thing.I've created #9266 to use retina size by default, and to allow users to scale it down to 1x with
ImageGrab.grab(bbox, scale_down=True).
Pillow/src/PIL/ImageGrab.py
Line 54 in 33eb16b
bboxis given. The reason is that the screenshot for a region 100x200 is a 200x400 image on a Macbook Pro which will scale the the region by 2. After the resizing, the image quality is reduced.If no
bboxis provide,grabfunction produces a 3024x1964 image for the whole screen instead of a 1512x982 image. The resulted image does not have its quality reduced.So the API has an inconsistent behavior. If
bboxis not given, the resulted screenshot image has a good quality. But ifbboxis given, the resulted screenshot image has a low quality.So I suggest to add option to control the scaling like what mss package has done. mss has
IMAGE_OPTIONSto control the scaling.See https://github.com/BoboTiG/python-mss/blob/main/CHANGELOG.md#1010-2025-08-16 for details.What are your OS, Python and Pillow versions?
python3 -m PIL.reportproduces: