hotwheel2007
hotwheel2007

Reputation: 91

How to take low-resolution screenshots in python

I am working on a simple program that will draw your computer screen as ASCII art, live, and am having some performance issues. The problem is that my computer's screen is very high resolution, so it takes a while for the screenshot to be created. Currently I take a full-res screenshot, then lower the resolution so that it can fit into ASCII art. Rather than lowering the resolution afterwards, is it possible to take a screenshot in a lowered resolution? I am currently using the PIL library, using ImageGrab.grab() to take the screenshot.

I am using OSX.

Thanks for any help you can give!

Upvotes: 0

Views: 547

Answers (1)

hc_dev
hc_dev

Reputation: 9377

From the docs of PIL.ImageGrab.grab():

bbox – What region to copy. Default is the entire screen. Note that on Windows OS, the top-left point may be negative if all_screens=True is used.

xdisplay – X11 Display address. Pass None to grab the default system screen. Pass "" to grab the default X11 screen on Windows or macOS.

Thus for a reduced dimension of the screenshot, you can

  • either reduce the bounding-box to take the screenshot from a smaller region of the entire screen only (parameter bbox)
  • or try to create a virtual display on your OS which has a lower resolution. Then take the screenshot from that smaller screen (parameter xdisplay)

See also:

  1. Ask Ubuntu: Taking screenshot of higher resolution than actual display resolution
  2. X11 docs: XRANDR man page for creating a virtual screen with lower resolution in X11

Upvotes: 2

Related Questions