HOWTO - Take a screenshot

From WikiDoc

For Gnome users, this is easy. Run Applications->Accessories->Take Screenshot.

If you don't have Gnome installed, it can be difficult figuring out how to take screenshots. Luckily there are a few ways to do it.

One way is to use xpaint. In the Xfce menu, it's Graphics->Xpaint. Click Canvas->Take snapshot... then draw a rectangle around any area of the screen to grab it. Then Xpaint gives you a window where you can edit your snapshot, and save it. The Gimp can also take screenshots.

Another way is to use ImageMagick. IM provides a utility called import which you can use to take screenshots:

$ import -window root screenshot.jpg

The above command will take a screenshot of the entire screen and save it in the current directory with the name screenshot###.png, where ### is the screenshot's number, which can be up to 100 (optionally, you can specify a file extension of a common image format and it'll save to that). To make things more convenient (or to not have a terminal window in the screenshot), you can make a script and add it to your menu. I made a file in my home directory called screenshot.sh. It looks like this:

#!/bin/sh

# screenshot.sh - Take a screenshot of the X windows screen
# uses ImageMagick to do the dirty work

if [ "$1" = "" ]; then
	FILETYPE="png"
else
	FILETYPE="$1"
fi

COUNT=1

while [ $COUNT -lt 100 ]; do
	if [ -e "screenshot${COUNT}.${FILETYPE}" ]; then
		COUNT=$(expr $COUNT + 1)
	else
		break
	fi
done

if [ -e "screenshot${COUNT}.${FILETYPE}" ]; then
	echo "Too many screenshots! Rename some or move them."
	exit
else
	import -window root "screenshot${COUNT}.${FILETYPE}"
	if [ -x "/usr/bin/gqview" ]; then
		gqview "screenshot${COUNT}.${FILETYPE}"
	fi
fi

Or, alternatively (which will not limit the number of screenshots, instead using the date and time in the filename)

#!/bin/bash

# screenshot.sh - Take a screenshot.
# Author: Barret Rennie
# Released to the public domain.
# Modified from code on: http://wikidoc.kateos.org/index.php/HOWTO_-_Take_a_screenshot
# Uses date to create a unique snapshot filename
# Uses ImageMagick to "do the dirty work"
# Edit before running to suit your needs

# Change this to where you want to save screenshots, include trailing /
OUTPUT="~/"

if [ ! -x "/usr/bin/import" ]; then
    echo "Please install ImageMagick."
    exit
fi

# Determine Filetype

if [ "$1" = "" ]; then
    FILETYPE="png"
else
    FILETYPE="$1"
fi

# Get timestamp: YYYY-MM-DD_HH-MM-SS
STAMP=`date +"%Y-%m-%d_%H-%M-%S"`

while [ -e "${OUTPUT}screenshot${STAMP}.${FILETYPE}" ]; do
    # Uncomment the following line to be verbose
    # echo "Screenshot '${OUTPUT}screenshot${STAMP}.${FILETYPE} already exists..."
    sleep 1
    STAMP=`date +"%Y-%m-%d_%H-%M-%S"`
done

import -window root "${OUTPUT}screenshot${STAMP}.${FILETYPE}"

echo "Screenshot saved to: '${OUTPUT}screenshots${STAMP}.${FILETYPE}'."

# Uncomment the following lines to view the image after creating
# if [ -x "/usr/bin/gqview" ]; then
#    gqview "${OUTPUT}screenshot${STAMP}.${FILETYPE}"& > /dev/null #Run as background process
# fi

After it's saved, make it executable by running:

$ chmod +x screenshot.sh

Then go to ~/.local/share/applications and make a screenshot.desktop file that looks like this:

[Desktop Entry]
Encoding=UTF-8
Name=Screenshot
Comment=Take a screenshot
Exec=/home/(your username)/screenshot.sh
Terminal=false
Type=Application
Categories=Application;Utility;

just change "(your username)" to your actual username.

Now you'll have a handy screenshot entry in your Xfce menu Accessories->Screenshot. You can also use it from a terminal, like this:

$ ~/screenshot.sh jpg

That will take the screenshot and save it as a jpeg image. If you omit the jpg part, it'll take a png image instead. Works with bmp, gif, etc., too.