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

PIL.ImageGrab.grabclipboard() is lossy on Mac #7214

Closed
abey79 opened this issue Jun 15, 2023 · 1 comment · Fixed by #7219
Closed

PIL.ImageGrab.grabclipboard() is lossy on Mac #7214

abey79 opened this issue Jun 15, 2023 · 1 comment · Fixed by #7219
Labels

Comments

@abey79
Copy link
Contributor

abey79 commented Jun 15, 2023

Issue

On Mac, PIL.ImageGrab.grabclipboard() is lossy because it uses JPG:

commands = [
            'set theFile to (open for access POSIX file "'
            + filepath
            + '" with write permission)',
            "try",
            "    write (the clipboard as JPEG picture) to theFile",
            "end try",
            "close access theFile",
        ]

This results in lossy acquisition, which can be highly undesirable.

One such cases is when dealing with screenshots. The noise induced by the JPG conversion on otherwise relatively flat image content eventually leads to much bigger PNG output (if such format is desired in the end).

This can be easily fixed with the following change:

commands = [
            'set theFile to (open for access POSIX file "' + filepath + '" with write permission)',
            "try",
            "    write (the clipboard as «class PNGf») to theFile",
            "end try",
            "close access theFile",
        ]

Happy to submit a PR if there is willingness to apply this change.

What are your OS, Python and Pillow versions?

  • OS: macOS Ventura
  • Python: 3.11
  • Pillow: 9.5
@radarhere
Copy link
Member

Sure, sounds like a reasonable change. Feel free to create a PR

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

Successfully merging a pull request may close this issue.

2 participants