Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for RGBA pixel matching #23

Merged
merged 1 commit into from
Jun 11, 2017

Conversation

novel-yet-trivial
Copy link
Contributor

Sometimes the _screenshot_osx() function returns a image in rgba mode. I don't have a mac, but this was seen by someone I was helping on /r/learnpython, who was using El Capitan 10.6.8 and Python 3.5.1.

This update checks for the number of arguments the screenshot function returns, and adds the comparison of the alpha value if both the screenshot and the test value include it.

Please test; I don't have a mac and can't test it well.

@feigaoxyz
Copy link

confirm this problem

In [6]: pyscreeze.screenshot().getpixel((1200, 500))
Out[6]: (53, 75, 82, 255)

Which leads to a problem in pyautogui as well:

In [23]: pyautogui.pixelMatchesColor(1620, 650, (5, 40, 51))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-23-fd3781ddc9da> in <module>()
----> 1 pyautogui.pixelMatchesColor(1620, 650, (5, 40, 51))

/Users/user/.local/opt/pyenv/versions/miniconda3-latest/lib/python3.6/site-packages/pyscreeze/__init__.py in pixelMatchesColor(x, y, expectedRGBColor, tolerance)
    403
    404 def pixelMatchesColor(x, y, expectedRGBColor, tolerance=0):
--> 405     r, g, b = screenshot().getpixel((x, y))
    406     exR, exG, exB = expectedRGBColor
    407

@NinjaOnRails
Copy link

NinjaOnRails commented Jun 10, 2017

I had the same problem. novel-yet-trivial's solution fixed it for me. I'm on macOS Sierra running python 3.6.1

@asweigart asweigart merged commit 987c83f into asweigart:master Jun 11, 2017
@asweigart
Copy link
Owner

Merged this and it will be part of the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants