Last active
September 25, 2023 09:31
-
-
Save smellslikeml/b9ce80c358d583f85798155c6a01019f to your computer and use it in GitHub Desktop.
hidden screenshot with xlib and PIL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
from Xlib import display, X | |
from PIL import Image | |
dsp = display.Display() | |
screen = dsp.screen() | |
W = screen.width_in_pixels | |
H = screen.height_in_pixels | |
root = screen.root | |
raw = root.get_image(0, 0, W, H, X.ZPixmap, 0xffffffff) | |
image = Image.frombytes("RGB", (W, H), raw.data, "raw", "BGRX") | |
file_path = os.path.join(os.environ['HOME'], '.screenshot.png') | |
image.save(file_path) |
That's right, thanks!
Updating to be more concise using your suggestion.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can simply get resolution of screen by dsp.screen().width_in_pixels, dsp.screen().height_in_pixels