Introduction
One of the possibilities of taking screenshots in Linux is using
, a utility of the X Window System.
I just want to give a short overview on how to take interactive and non-interactive screenshots, view them and convert them to different formats.
Taking Screenshots
To take a screenshot you could just open a terminal and type ”
“, but by default
does not save the screenshot to a file (it outputs the image to stdout). To save the screenshot in a file, you can either use the
option of
:
xwd -out <filename>
or redirect the output of
to a file using the functionality offered by the shell:
xwd > <filename>
Just replace
with the name of the file you want to use for your screenshot. Examples:
xwd -out myshot.xwd
or
xwd > myshot.xwd
Notice the changed mouse pointer after typing one of these commands ? That’s because you now need to select the window of which you want to take a screenshot. The format
uses for the images it is called “X Window Dump” and the extension often used is
. I will cover the subject of converting the images to different formats (like JPEG or PNG) later.
Including the Window Frame
If you want to include the frame of the window in the screenshot, you have to add the
option. For example:
xwd -frame -out myshot.xwd
or
xwd -frame > myshot.xwd
Taking Screenshots Of The Whole Desktop
If you want to create a screenshot of the whole desktop instead of a single window, you can use the
option for that:
xwd -root -out myshot.xwd
or
xwd -root > myshot.xwd
Automated Screenshots Without Selecting The Window
It’s also possible to create screenshots of windows without the need to select them every time. This is especially useful if you want to make numerous screenshots of a single window (e.g. for a tutorial, a presentation, an article etc.).
To do this, you have to tell xwd which window you want to take a screenshot of on the command line, so that it does not have to ask. You can do this either by using the “resource id” of the window or the ”
property”. The value of the
property basically is the title of your window as it is displayed in the window title bar. Using this to create screenshots can be problematic (With Firefox, for example, this value depends on the title of the active tab, so going to a different tab will change the
property of the window).
To determine the resource id or the value of the
property, you can use the
tool. Just type this in the terminal:
xwininfo
And then, similar to
, click on the window you are interested in. It will then display a bunch of information about the window, which might look like this:
xwininfo: Window id: 0x40000e7 "Home of the Mozilla Project - Mozilla Firefox" Absolute upper-left X: 1287 Absolute upper-left Y: 70 Relative upper-left X: 0 Relative upper-left Y: 0 Width: 1159 Height: 1501 Depth: 24 Visual: 0x21 Visual Class: TrueColor Border width: 0 Class: InputOutput Colormap: 0x20 (installed) Bit Gravity State: NorthWestGravity Window Gravity State: NorthWestGravity Backing Store State: NotUseful Save Under State: no Map State: IsViewable Override Redirect State: no Corners: +1287+70 -114+70 -114-29 +1287-29 -geometry 1159x1501+1279-21
The red and blue color was something I added for clarification. The red thing is the resource ID we are interested in and the blue thing is the
property that we also could use.
If we wanted to use the resource ID, we would do it like this
xwd -id -out myshot.xwd
If we want to use the WM_NAME property, we would do this:
xwd -name -out myshot.xwd
One important thing to note about this approach is that using the -frame option for xwd does not have any effect if you supply the id or name as well. That is, because the resource id for both cases is different. Therefore, if you want to include the window frame, you have to supply the
option to
to retrieve the correct resource id. You would then type:
xwininfo -frame
Just to show you that they really differ: In my case, right now, running
xwininfo
gives me:
xwininfo: Window id: 0x40000e7 "Home of the Mozilla Project - Mozilla Firefox"
while running
xwininfo -frame
and clicking on the same, unchanged window, gives me:
xwininfo: Window id: 0xe002df (has no name).
Viewing Screenshots
You can view the
-screenshots directly with the tool
. Just type:
xwud <filename>
for example:
xwud screenshot.xwd
Converting and Editing Screenshots
Converting Screenshots
You can easily convert the screenshots to “normal” image formats like JPEG or PNG with tools like ImageMagick. If you don’t have ImageMagick installed, it should be available through your repositories. For example, in Ubuntu/Debian you would simply type:
sudo aptitude install imagemagick
or
sudo apt-get install imagemagick
Once you have ImageMagick installed, you can convert an
image by using
. For example, to convert an
-screenshot named
to a JPEG file named
, type:
convert shot.xwd shot.jpg
You can convert the image to other formats as well, like PNG for example:
convert sot.xwd shot.png
Editing Screenshots
I won’t include a tutorial on editing screenshots here, but I just wanted to mention that you might not have to convert your screenshots to JPG or PNG (or something else) in order to edit them, because your image editor might already be able to load
files. GIMP, for example, can open them directly.
Detailed and helpful. Thank you!
Thanks a lot for your tutorial. It helped me a lot.
Really detailed tutorial – thanks for your effort!