Skip to content

ImageGrab.grab() region issue #7677

@JacobHagberg

Description

@JacobHagberg

What did you do?

Used image grab on Mac OS, and the region input seems to not handle anything above a certain y1 value

What did you expect to happen?

I expect the region of the ImageGrab.grab() to return an image of the screen of the region specified, but it throws an error

What actually happened?

It threw an rect (836.0, 982.0, 500.0, 218.0) does not intersect any displays error

What are your OS, Python and Pillow versions?

  • OS: Mac OS 13.4, M1 Pro
  • Python: 3.11.1
  • Pillow: 10.1.0

This code takes an image of the region [836, i, 1336, 1200]. where i is incremented upward until i=982, where it throws an error. The result of print(image1.size) is (3024, 1964) BTW. Not sure what is going on here, please reach out if you have further questions.

from PIL import ImageGrab image1 = ImageGrab.grab() print(image1.size) for i in range(950, 1050): image2 = ImageGrab.grab([836, i, 1336, 1200]) print(i) print(image2.size)

output:

973 (500, 227) 974 (500, 226) 975 (500, 225) 976 (500, 224) 977 (500, 223) 978 (500, 222) 979 (500, 221) 980 (500, 220) 981 (500, 219) rect (836.0, 982.0, 500.0, 218.0) does not intersect any displays Traceback (most recent call last): File "/Users/jacobhagberg/Documents/PythonCode/EveOnlineAutopilot/QuickTest.py", line 7, in <module> image2 = ImageGrab.grab([836, i, 1336, 1200]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/PIL/ImageGrab.py", line 38, in grab im = Image.open(filepath) ^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/PIL/Image.py", line 3305, in open raise UnidentifiedImageError(msg) PIL.UnidentifiedImageError: cannot identify image file '/var/folders/2t/fyymv8314fn56nytzjvtq93r0000gn/T/tmpxroi8hx0.png'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions