Difference between revisions of "Taking a screenshot"

From ArchWiki
Jump to: navigation, search
(This 'script' can be really useful to capture ansi codes from the terminal)
(Improving the style)
Line 4: Line 4:
 
[[ru:Taking a Screenshot]]
 
[[ru:Taking a Screenshot]]
 
[[zh-CN:Taking a Screenshot]]
 
[[zh-CN:Taking a Screenshot]]
== import ==
+
This article explain different methods to take [[Wikipedia:Screenshot|screenshots]] on your system.
 +
== General methods ==
 +
=== import ===
 
An easy way to take a screenshot of your current system is using the {{Ic|import}} command:
 
An easy way to take a screenshot of your current system is using the {{Ic|import}} command:
import -window root screenshot.jpg
+
{{bc|$ import -window root screenshot.jpg}}
  
 
{{Ic|import}} is part of the {{Pkg|imagemagick}} package.
 
{{Ic|import}} is part of the {{Pkg|imagemagick}} package.
Line 12: Line 14:
 
Running {{Ic|import}} without the {{Ic|-window}} option allows selecting a window or an arbitrary region interactively.
 
Running {{Ic|import}} without the {{Ic|-window}} option allows selecting a window or an arbitrary region interactively.
  
=== Screenshot of multiple X screens ===
+
==== Screenshot of multiple X screens ====
 
If you run twinview or dualhead, simply take the screenshot twice and use {{Ic|imagemagick}} to paste them together:
 
If you run twinview or dualhead, simply take the screenshot twice and use {{Ic|imagemagick}} to paste them together:
import -window root -display :0.0 -screen /tmp/0.png
+
{{bc|
import -window root -display :0.1 -screen /tmp/1.png
+
import -window root -display :0.0 -screen /tmp/0.png
convert +append /tmp/0.png /tmp/1.png screenshot.png
+
import -window root -display :0.1 -screen /tmp/1.png
rm /tmp/{0,1}.png
+
convert +append /tmp/0.png /tmp/1.png screenshot.png
 +
rm /tmp/{0,1}.png
 +
}}
  
=== Screenshot of individual Xinerama heads ===
+
==== Screenshot of individual Xinerama heads ====
 
Xinerama-based multi-head setups have only one virtual screen. If the physical screens are different in height, you will find dead space in the screenshot. In this case, you may want to take screenshot of each physical screen individually. As long as Xinerama information is available from the X server, the following will work:
 
Xinerama-based multi-head setups have only one virtual screen. If the physical screens are different in height, you will find dead space in the screenshot. In this case, you may want to take screenshot of each physical screen individually. As long as Xinerama information is available from the X server, the following will work:
  #!/bin/bash
+
{{bc|<nowiki>
  xdpyinfo -ext XINERAMA | sed '/^  head #/!d;s///' |
+
#!/bin/bash
  while IFS=' :x@,' read i w h x y; do
+
xdpyinfo -ext XINERAMA | sed '/^  head #/!d;s///' |
 +
while IFS=' :x@,' read i w h x y; do
 
     import -window root -crop ${w}x$h+$x+$y head_$i.png
 
     import -window root -crop ${w}x$h+$x+$y head_$i.png
  done
+
done
 +
</nowiki>}}
  
=== Screenshot of the active/focused window ===
+
==== Screenshot of the active/focused window ====
 
The following script takes a screenshot of the currently focused window. It works with EWMH/NetWM compatible X Window Managers. To avoid overwriting previous screenshots, the current date is used as the filename.
 
The following script takes a screenshot of the currently focused window. It works with EWMH/NetWM compatible X Window Managers. To avoid overwriting previous screenshots, the current date is used as the filename.
  #!/bin/bash
+
{{bc|<nowiki>
  activeWinLine=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)")
+
#!/bin/bash
  activeWinId=${activeWinLine:40}
+
activeWinLine=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)")
  import -window "$activeWinId" /tmp/$(date +%F_%H%M%S_%N).png
+
activeWinId=${activeWinLine:40}
 +
import -window "$activeWinId" /tmp/$(date +%F_%H%M%S_%N).png
 +
</nowiki>}}
  
 
Alternatively, the following should work regardless of EWMH support:
 
Alternatively, the following should work regardless of EWMH support:
  import -window "$(xdotool getwindowfocus -f)" /tmp/$(date +%F_%H%M%S_%N).png
+
{{bc|$ import -window "$(xdotool getwindowfocus -f)" /tmp/$(date +%F_%H%M%S_%N).png}}
  
== GIMP ==
+
=== GIMP ===
You also can take screenshots with GIMP (File -> Create -> Screenshot...).
+
You also can take screenshots with GIMP ('''File''' -> '''Create''' -> '''Screenshot'''...).
  
== xwd ==
+
=== xwd ===
 
xwd is part of the {{Pkg|xorg-xwd}} package.
 
xwd is part of the {{Pkg|xorg-xwd}} package.
  
 
Take a screenshot of the root window:
 
Take a screenshot of the root window:
xwd -root -out screenshot.xwd
+
{{bc|$ xwd -root -out screenshot.xwd}}
  
See the xwd man page for more information.
+
See the {{ic|man xwd}} for more information.
  
== scrot ==
+
=== scrot ===
  
 
{{Note|According [http://comments.gmane.org/gmane.comp.misc.suckless/6901 This Thread], {{Pkg|scrot}} does not work with {{Pkg|dwm}} nor {{Pkg|xbindkeys}}.}}
 
{{Note|According [http://comments.gmane.org/gmane.comp.misc.suckless/6901 This Thread], {{Pkg|scrot}} does not work with {{Pkg|dwm}} nor {{Pkg|xbindkeys}}.}}
Line 54: Line 62:
  
 
{{Pkg|scrot}}, which is available in the [[Official Repositories|official repositories]], enables taking screenshots from the CLI and offers features such as a user-definable time delay. Unless instructed otherwise, it saves the file in the current working directory.
 
{{Pkg|scrot}}, which is available in the [[Official Repositories|official repositories]], enables taking screenshots from the CLI and offers features such as a user-definable time delay. Unless instructed otherwise, it saves the file in the current working directory.
scrot -t 20 -d 5
+
{{bc|$ scrot -t 20 -d 5}}
  
 
The above command saves a dated {{ic|.png}} file, along with a thumbnail (20% of original), for Web posting. It provides a 5 second delay before capturing in this instance.
 
The above command saves a dated {{ic|.png}} file, along with a thumbnail (20% of original), for Web posting. It provides a 5 second delay before capturing in this instance.
  
 
You can also use standard date and time formatting when saving to a file.  e.g.,
 
You can also use standard date and time formatting when saving to a file.  e.g.,
scrot ~/screenshots/%Y-%m-%d-%T-screenshot.png
+
{{bc|$ scrot ~/screenshots/%Y-%m-%d-%T-screenshot.png}}
  
 
saves the screenshot in a filename with the current year, month, date, hours, minutes, and seconds to a folder in your home directory called "screenshots"  
 
saves the screenshot in a filename with the current year, month, date, hours, minutes, and seconds to a folder in your home directory called "screenshots"  
  
See {{Ic|man scrot}} for more information. You can simply automate the file to uploaded like so https://github.com/kaihendry/Kai-s--HOME/tree/master/bin
+
See {{Ic|man scrot}} for more information. You can simply automate the file to uploaded like so {{ic|https://github.com/kaihendry/Kai-s--HOME/tree/master/bin}}
  
== imlib2 ==
+
=== imlib2 ===
  
 
{{Pkg|imlib2}} provides a binary {{ic|imlib2_grab}} to take screenshots.  To take a screenshot of the full screen, type:
 
{{Pkg|imlib2}} provides a binary {{ic|imlib2_grab}} to take screenshots.  To take a screenshot of the full screen, type:
imlib2_grab screenshot.png
+
{{bc|$ imlib2_grab screenshot.png}}
  
Note that {{Pkg|scrot}} actually uses imlib2.
+
Note that {{Pkg|scrot}} actually uses {{ic|imlib2}}.
 
+
== Desktop environment specific ==
== KDE ==
+
=== KDE ===
If you use [[KDE]], you might want to use KSnapshot, which can also be activated using <Prt Scr>.
+
If you use [[KDE]], you might want to use {{ic|KSnapshot}}, which can also be activated using {{keypress|Prnt Scr}}.
  
 
KSnapshot is provided by the {{Pkg|kdegraphics-ksnapshot}} package in [extra].
 
KSnapshot is provided by the {{Pkg|kdegraphics-ksnapshot}} package in [extra].
  
== Xfce ==
+
=== Xfce ===
  
 
If you use [[Xfce]] you can install {{Pkg|xfce4-screenshooter}} and then add a keyboard binding:
 
If you use [[Xfce]] you can install {{Pkg|xfce4-screenshooter}} and then add a keyboard binding:
Xfce Menu  -->  Settings  -->  Keyboard  >>>  Application Shortcuts.
 
  
If you want to skip the Screenshot prompt, type {{ic|xfce4-screenshooter -h}} in terminal for the options.
+
'''Xfce Menu'''  -->  '''Settings'''  -->  '''Keyboard'''  >>>  '''Application Shortcuts'''.
 +
 
 +
If you want to skip the Screenshot prompt, type {{ic|$ xfce4-screenshooter -h}} in terminal for the options.
  
== GNOME ==
+
=== GNOME ===
[[GNOME]] users can press <Prt Scr> or Apps->Accessories->Take Screenshot.
+
[[GNOME]] users can press {{keypress|Prn Scr}} or Apps->Accessories->Take Screenshot.
  
{{Note|If <Prt Scr> complains about not finding gnome-screenshot or there is no "Take Screenshot" entry in your menu, you will need to install the {{Pkg|gnome-utils}} package from [extra].}}
+
{{Note|If {{keypress|Prnt Scr}} complains about not finding {{ic|gnome-screenshot}} or there is no "Take Screenshot" entry in your menu, you will need to install the {{Pkg|gnome-utils}} package from [extra].}}
  
== Other Desktop Environments or Window Managers ==
+
=== Other Desktop Environments or Window Managers ===
 
For other desktop environments such as [[LXDE]] or window managers such as [[Openbox]] and [[Compiz]], one can add the above commands to the hotkey to take the screenshot. For example,
 
For other desktop environments such as [[LXDE]] or window managers such as [[Openbox]] and [[Compiz]], one can add the above commands to the hotkey to take the screenshot. For example,
import -window root ~/Pictures/`date '+%Y%m%d-%H%M%S'`.png
+
{{bc|$ import -window root ~/Pictures/`date '+%Y%m%d-%H%M%S'`.png}}
Adding the above command to the <Prt Scr> key to Compiz allows to take the screenshot to the Pictures folder according to date and time.
+
Adding the above command to the {{keypress|Prnt Scr}} key to Compiz allows to take the screenshot to the Pictures folder according to date and time.
Notice that the {{ic|rc.xml}} file in Openbox does not understand commas; so, in order to bind that command to the <Prt Scr> key in Openbox, you need to add the following to the keyboard section of your {{ic|rc.xml}} file:
+
Notice that the {{ic|rc.xml}} file in Openbox does not understand commas; so, in order to bind that command to the {{keypress|Prnt Scr}} key in Openbox, you need to add the following to the keyboard section of your {{ic|rc.xml}} file:
  
<nowiki><!-- Screenshot --></nowiki>
+
{{hc|rc.xml|<nowiki>
 +
<!-- Screenshot -->
 
     <keybind key="Print">
 
     <keybind key="Print">
 
       <action name="Execute">
 
       <action name="Execute">
Line 101: Line 111:
 
       </action>
 
       </action>
 
     </keybind>
 
     </keybind>
 +
</nowiki>}}
 
== Terminal ==
 
== Terminal ==
 
=== Output with ansi codes ===
 
=== Output with ansi codes ===
Line 109: Line 120:
  
 
If you merely want to capture the text in the console and not an actual image, you can use {{Ic|setterm}}, which is part of the {{Pkg|util-linux}} package.  The following command will dump the textual contents of virtual console 1 to a file screen.dump in the current directory:
 
If you merely want to capture the text in the console and not an actual image, you can use {{Ic|setterm}}, which is part of the {{Pkg|util-linux}} package.  The following command will dump the textual contents of virtual console 1 to a file screen.dump in the current directory:
sudo setterm -dump 1 -file screen.dump
+
{{bc|# setterm -dump 1 -file screen.dump}}
  
 
Root permission is needed because the contents of {{ic|/dev/vcs1}} need to be read.
 
Root permission is needed because the contents of {{ic|/dev/vcs1}} need to be read.

Revision as of 08:00, 3 January 2013

This article explain different methods to take screenshots on your system.

General methods

import

An easy way to take a screenshot of your current system is using the import command:

$ import -window root screenshot.jpg

import is part of the imagemagick package.

Running import without the -window option allows selecting a window or an arbitrary region interactively.

Screenshot of multiple X screens

If you run twinview or dualhead, simply take the screenshot twice and use imagemagick to paste them together:

import -window root -display :0.0 -screen /tmp/0.png
import -window root -display :0.1 -screen /tmp/1.png
convert +append /tmp/0.png /tmp/1.png screenshot.png
rm /tmp/{0,1}.png

Screenshot of individual Xinerama heads

Xinerama-based multi-head setups have only one virtual screen. If the physical screens are different in height, you will find dead space in the screenshot. In this case, you may want to take screenshot of each physical screen individually. As long as Xinerama information is available from the X server, the following will work:

#!/bin/bash
xdpyinfo -ext XINERAMA | sed '/^  head #/!d;s///' |
while IFS=' :x@,' read i w h x y; do
    import -window root -crop ${w}x$h+$x+$y head_$i.png
done

Screenshot of the active/focused window

The following script takes a screenshot of the currently focused window. It works with EWMH/NetWM compatible X Window Managers. To avoid overwriting previous screenshots, the current date is used as the filename.

#!/bin/bash
activeWinLine=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)")
activeWinId=${activeWinLine:40}
import -window "$activeWinId" /tmp/$(date +%F_%H%M%S_%N).png

Alternatively, the following should work regardless of EWMH support:

$ import -window "$(xdotool getwindowfocus -f)" /tmp/$(date +%F_%H%M%S_%N).png

GIMP

You also can take screenshots with GIMP (File -> Create -> Screenshot...).

xwd

xwd is part of the xorg-xwd package.

Take a screenshot of the root window:

$ xwd -root -out screenshot.xwd

See the man xwd for more information.

scrot

Note: According This Thread, scrot does not work with dwm nor xbindkeys.


scrot, which is available in the official repositories, enables taking screenshots from the CLI and offers features such as a user-definable time delay. Unless instructed otherwise, it saves the file in the current working directory.

$ scrot -t 20 -d 5

The above command saves a dated .png file, along with a thumbnail (20% of original), for Web posting. It provides a 5 second delay before capturing in this instance.

You can also use standard date and time formatting when saving to a file. e.g.,

$ scrot ~/screenshots/%Y-%m-%d-%T-screenshot.png

saves the screenshot in a filename with the current year, month, date, hours, minutes, and seconds to a folder in your home directory called "screenshots"

See man scrot for more information. You can simply automate the file to uploaded like so https://github.com/kaihendry/Kai-s--HOME/tree/master/bin

imlib2

imlib2 provides a binary imlib2_grab to take screenshots. To take a screenshot of the full screen, type:

$ imlib2_grab screenshot.png

Note that scrot actually uses imlib2.

Desktop environment specific

KDE

If you use KDE, you might want to use KSnapshot, which can also be activated using Template:Keypress.

KSnapshot is provided by the kdegraphics-ksnapshot package in [extra].

Xfce

If you use Xfce you can install xfce4-screenshooter and then add a keyboard binding:

Xfce Menu --> Settings --> Keyboard >>> Application Shortcuts.

If you want to skip the Screenshot prompt, type $ xfce4-screenshooter -h in terminal for the options.

GNOME

GNOME users can press Template:Keypress or Apps->Accessories->Take Screenshot.

Note: If Template:Keypress complains about not finding gnome-screenshot or there is no "Take Screenshot" entry in your menu, you will need to install the gnome-utils package from [extra].

Other Desktop Environments or Window Managers

For other desktop environments such as LXDE or window managers such as Openbox and Compiz, one can add the above commands to the hotkey to take the screenshot. For example,

$ import -window root ~/Pictures/`date '+%Y%m%d-%H%M%S'`.png

Adding the above command to the Template:Keypress key to Compiz allows to take the screenshot to the Pictures folder according to date and time. Notice that the rc.xml file in Openbox does not understand commas; so, in order to bind that command to the Template:Keypress key in Openbox, you need to add the following to the keyboard section of your rc.xml file:

rc.xml
<!-- Screenshot -->
    <keybind key="Print">
      <action name="Execute">
        <command>sh -c "import -window root ~/Pictures/`date '+%Y%m%d-%H%M%S'`.png"</command>
      </action>
    </keybind>

Terminal

Output with ansi codes

You can use the script command, part of the util-linux package.

Just enter
$ script
and all the input/output is going to be saved to the typescript file, including the ansi codes.

Virtual console

Install a framebuffer and use fbgrab, fbshot, or fbdump to take a screenshot.

If you merely want to capture the text in the console and not an actual image, you can use setterm, which is part of the util-linux package. The following command will dump the textual contents of virtual console 1 to a file screen.dump in the current directory:

# setterm -dump 1 -file screen.dump

Root permission is needed because the contents of /dev/vcs1 need to be read.