IgnorantGuru's Blog

Linux software, news, and tips

Screen Snapshots Using XWD

In KDE Free I described using Imagemagick’s “import” to take window and screen snapshots as a replacement for KSnapshot. Since then I have had problems with import leaving black areas on the snapshots, as another person describes here.

So I am now using X’s xwd instead, with the output piped through Imagemagick’s “convert”. Works with any DE. To set this as a keyboard shortcut in Openbox’s rc.xml:

  <keybind key="Print">
    <action name="Execute">
      <startupnotify>
        <enabled>false</enabled>
        <name>Snapshot</name>
      </startupnotify>
      <command>bash -c "xwd | convert - /tmp/screenshot-$(date +%s).png"</command>
    </action>
  </keybind>
  <keybind key="S-Print">
    <action name="Execute">
      <startupnotify>
        <enabled>false</enabled>
        <name>Snapshot with Frame</name>
      </startupnotify>
      <command>bash -c "xwd -frame | convert - /tmp/screenshot-$(date +%s).png"</command>
    </action>
  </keybind>
  <keybind key="C-Print">
    <action name="Execute">
      <startupnotify>
        <enabled>false</enabled>
        <name>Snapshot Fullscreen</name>
      </startupnotify>
      <command>bash -c "xwd -root | convert - /tmp/screenshot-$(date +%s).png"</command>
    </action>
  </keybind>

This makes the Printscreen key take a snapshot of window contents, Shift-Printscreen include the window frame, and Ctrl-Printscreen capture the whole screen. You can also use a .jpg extension for that format instead of .png, and can change /tmp to any folder where you want the screenshots saved.

And you’ll need to install imagemagick, of course.

June 7, 2010 - Posted by | Tips

2 Comments

  1. Thank you very much, very useful tip. I had no idea about the Xwd command. I’m using dwm BTW.

    Comment by PresupuestosPC | July 22, 2010

  2. Solutions
    1) xwd + imagemagick, as described here

    2) xwd + netpbm
    $ xwd | xwdtopnm | pnmtopng > screenshot.png

    xwdtopnm and pnmtopng are programs from netpbm package (http://www.archlinux.org/packages/extra/i686/netpbm) which is lighter than imagemagick (http://www.archlinux.org/packages/extra/i686/imagemagick)
    According to archlinux package database, imagemagick’s installed size is 9.0 MB, and netpbm’s – 6.3 MB, BUT netpbm depends on perl (well-known programming language) which has 55 MB of installed size.

    So the question about, what solution is ligher, still open.

    3) scrot.
    Ultra-light soultion. But I have some issues making screenshots of separate windows (Arch + LXDE) when terminal window with scrot olerlaps the window I want to shoot.

    Comment by BrainWorker | March 27, 2011


Sorry, the comment form is closed at this time.