Welcome, guest | Sign In | My Account | Store | Cart

Dump an arbitrary widget to an image file of (almost) any kind by using XWD and ImageMagick.

Tcl, 15 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
proc dumpWidget {window filename args} {
    # What is the X id of the window to dump?
    set id [winfo id $window]

    # We'll use xwd to do the actual dump...
    set cmd [list exec xwd -quiet -id $id]

    # ...and ImageMagick to convert to whatever...
    lappend cmd | convert

    # ...but we need to be a little careful when inserting the
    # arguments and handling the filenames since they are
    # not guaranteed to be well-behaved words...
    eval $cmd $args [list - $filename]
}

example usage: dumpWidget .foo.bar foobar.png -swirl 60 -interlace partition

OK, so the above looks somewhat drunken when applied to a whole screen, but it does demonstrate the capabilities quite well. :^)

Note that the window to be dumped must be raised to the top first or you will dump whatever is viewable on top of it as well; this is an X restriction, so there is very little you can do to work around it.

Created by Donal Fellows on Tue, 11 Sep 2001 (MIT)
Tcl recipes (162)
Donal Fellows's recipes (6)

Required Modules

  • (none specified)

Other Information and Tasks