| Xvfb acts like a normal X server, but insted of writing the output to the graphics adapter, it writes the graphical output in a binary format into memory. This gives us the opportunity to capture any window running at the Xvfb DISPLAY. Xvfb is included in standard Xorg installations and can be run with a couple of basic parameters. Xvfb :1 -screen 0 1400x2000x24
This tells the Xvfb to run on DISPLAY number 1 and screen number 0 with resolution width of 1400 and height 2000 in 24 bit color depth. Now we can capture the screen of any window running in the Xvfb DISPLAY/screen with xwd utility. We have to tell the xwd which screen to capture by either setting the DISPLAY environment variable: export DISPLAY=:1.0 or by adding a -display and -screen parameters to the xwd tool. Taking the first approach we issue:
xwd -root -silent > screen.xwd
Now we have a binary file screen.xwd. In order to convert the xwd file to more convenient format we have 2 utilities - xwdtopnm and pnmtojpeg. The first converts the xwd to pnm and the second from pnm to jpeg image format. Now to put it all together: xwd -root -silent | xwdtopnm |pnmtojpeg > screen.jpg |