How to take screenshot of an X11 based GUI from a text terminal (such as tty1)?
I tried using DISPLAY=:0 import -window root "$HOME/Pictures/screenshot.png"
(import
is part of the ImageMagick suite), but that just displays a black screen.
I want to do this as I wanted to automate opening an app and taking screenshots of it in different languages, and to change languages, I need to restart lightdm. therefore, run on a tty so your script continues running...
Solution 1:
In addition to the existing answers, to display the screenshot in ASCII in the terminal:
xwd -root -display :0 | convert - jpg:- | jp2a - --colors
(Requires x11-apps
for xwd
, imagemagick
for convert
and jp2a
.)
Solution 2:
Here is solution using xwd
, which is is available in almost all Xorg installations:
xwd -root -out screenshot.xwd
The screenshot.xwd
file can be opened with GIMP:
For more info see http://www.x.org/wiki/UserDocumentation/GettingStarted/.