[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

How To Take a Screenshot ?

Taking a screenshot can be done in several ways.
The easiest is to use a graphics program (for example KSnapshot, The GIMP, or xpaint) and choose the built-in screenshot or snapshot menu option. The method may be very different from one application to another, so I have chosen xpaint as an example.

But you can't use this program to make a screenshot of a video or an image in full-screen, for example. To circumvent this, you can use the PrtScr key (aka Print Screen), or use some command-line tools designed for the X window system. I'll quickly describe the basic switches of an X tool called xwd, and Imagemagick's import command.

Using the Import Function of an Application

I will explain here how to do it with xpaint, a pretty lightweight piece of software that has the basic tools you would need to work on a screenshot. You do not need all the power of The GIMP to make some basic changes to a screenshot. Plus it's already included in a default Slackware install.

Open xpaint from an xterm, or from your DE / WM menu. Open the “Canvas” menu and select “Take snapshot”. A little edge appears, which will allow you to select the application window you are capturing. What happens next depends which mouse button you click on.

  • To capture the whole screen, left-click or middle-click somewhere on your desktop. To be precise, on a part of the desktop where you can see the desktop's background or background image.
  • To capture a specific window, left-click or middle-click somewhere in it.
  • To capture a specific area on the screen, left-click and hold it till you get the desired size.
  • To cancel a capture, right-click.
You can use the -screenshot switch to launch xpaint in the snapshot mode (xpaint -screenshot). This will provide the selection edge instantly, with no need to click through the menus. Can be useful as an alias if you are only using xpaint for screenshots.

The Keyboard Method

Press the PrtScr key, located usually on the top-right of your keyboard. It can also read PrnScr, Print Screen, etc. Open an image editing program (GIMP, xpaint, …), and choose the paste option, usually the Ctrl+V combo. On some systems, it has been reported that using Alt+PrtScr solves the problem.

Neither of these methods works on my system. I don't know yet if it's because of my hardware/laptop configuration or because of my X keyboard setup, so I can't guarantee that it will work on your system. Neither can I tell you if it's supposed to work on a tty. The article will eventually show the hint as I find out or someone else posts some suggestion(s).

The Command-Line Way

Please note that for the following commands to run, the Imagemagick suite of tools must be installed. Run slackpkg search imagemagick to check if it's installed on your system, but it's usually available with a normal Slackware install.

Even if you can launch the commands from a tty (using proper options not described in this document but in the man pages), only X windows may be captured.

The ''xwd'' Command

xwd is part of the X system. As it dumps the screenshot in a special format, we have to use an ImageMagick tool to convert it, named … convert.

Capturing a window

xwd | convert - path/to/screenshot.ext

You will be provided with a crosshair tool; use it to select the window you want to capture. You can change the type of the output file only by changing the extension, for example screenshot.png, screenshot.jpg, screenshot.gif, etc. The - switch is to indicate to convert that it should translate from standard input rather than a file.

Remember to raise the window you want to grab above the others. Otherwise every window which covers it will be replaced by black pixels (or black boxes) in the final capture. Which by the way can be an useful way to hide some parts of the output! For example if you take a screenshot of an xterm full of commands with some of your personal info displayed (passwords, IP addresses, …), or a screenshot of a browser and you want to hide some tabs. Just place some windows over the one you want to capture.

If you want to capture a window WITH its overlayered windows, so that the capture does not display a black box but instead the overlaying window(s) content (for example, an application menu or an xterm window over a browser to capture both at the same time, etc), use the -screen switch:

xwd -screen | convert - path/to/screenshot.ext

Capturing the Desktop or a Fullscreen Application

Add the -root switch to get:

''xwd -root | convert - path/to/screenshot.ext''

The -root indicates you want to grab the “main” X window, so all what you can see currently displayed on screen (root is the name of the main X window). As it's capturing the whole screen, you won't need to select a window.

Imagemagick's ''import'' Command

There may be a bug or at least a glitch on some systems, as import -screen and import -window root may show “black boxes” overlaying the window that has been captured, which indicates that some other window(s) are getting on top of it before the capture takes place, even if you don't see it/them!
I don't know what causes this behaviour, nor have found or really searched for an explanation yet. Nonetheless, it seems that the -frame switch works better, but it has the same limitations as -screen (you can't get overlaying windows content). You can also try to minimize all open windows.
If that doesn't help, use xwd for correct captures, or grab your hitchhiking guide and get on google.

The import command is part of the ImageMagick suite of tools. It works like xwd but doesn't need the convert program and uses different options (switches).

Capturing a window

import path/to/screenshot.ext

Select the desired window to capture, and that's it.

import -screen path/to/screenshot.ext
import -frame path/to/screenshot.ext

The -screen option is equivalent to xwd's one, having the same limitations for overlayed windows. The -frame switch cannot capture overlayed windows.

Capturing the Desktop or a Fullscreen Application

import -window root path/to/screenshot.ext
import -frame path/to/screenshot.ext

The -window root is equivalent to xwd's -root switch. It captures the whole desktop. The -frame option can be used to prevent black boxes as in the warning above.

Hints for Fullscreen Applications

To make these methods work for fullscreen applications, you have to prepend a sleep command before the actual commands, so you can switch windows before being prompted to choose the captured one. You then have some time to prepare the application you want to capture. For example, to take a screenshot of a fullscreen YouTube or mplayer-played video:

  • Type the screenshot command (for example sleep 15 ; xwd | convert - ~/YT-capture.png)
  • In the player/viewer, play the video or show the image
  • Choose the fullscreen view mode.
  • Wait for the crosshairs to display, then click. Your screenshot is now recorded.

You can use whatever command switches you like or even none - it's up to you. Without switches you'll have to click the window to capture, with any of them the screenshot will be taken just after the sleep countdown reaches 0.
If you are using the automated methods (ie. xwd -root or import -window root), you can add a bell after the command, so you know the operation is complete. The full command is then:

sleep 15 ; xwd -root | convert - path/to/screenshot.ext ; echo $'\a'

Or with import:

sleep 15 ; import -window root path/to/screenshot.ext ; echo $'\a'

To go further

The tools are well documented in their man pages, I recommend you to read them for fine tuning or better automation of your screenshots: man import, man xwd, man convert.
xwd has a corresponding program called xuwd. It reads an xwd dump (either from a dump file or from standard input) and displays it. It can be useful for automatic display of screenshots taken on remote machines, if you don't need to save the files.

I do not want to read all this article! I'm in a hurry!

Fair enough, shorter can be better, sometimes. Only xwd commands are shown though.

  • Capture the selected window (fullscreen or window mode): xwd | convert - path/to/screenshot.ext
  • Capture a screenshot of the whole X session: xwd -root | convert - path/to/screenshot.ext
  • Capture a window with the overlayed windows content: xwd -screen | convert - path/to/screenshot.ext
  • Add a timer before the command to be able to switch to a fullscreen application: sleep 10 ; xwd | convert - path/to/screenshot.ext


 howtos:window_managers:take_a_screenshot ()