Welcome to WebmasterWorld Guest from

Forum Moderators: incrediBILL

Message Too Old, No Replies

How can i create screenshot of url?

html to image in linux

2:29 pm on Nov 28, 2004 (gmt 0)

10+ Year Member

Hi everybody! This site is wonderful!

I've a web catalogue of links and i want to add function, that will create screens of this links (something like www.searchsight.com).
In what way can i easily create mini screenshots of this websites on linux server (using command line)?

Thanks for any replies.

11:31 pm on Nov 28, 2004 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Welcome to the forum, Peter. This topic came up just a few days ago [webmasterworld.com].

As I mentioned in that thread, you can check out this thread in our Perl/CGI forum for ideas:
Script to generate thumbnail [webmasterworld.com]


One way you can do it is you have a browser such as mozilla installed on the server, and you also have X running (and a window manager), you can get a screenshot this way:

Leave the browser window open, fully maximized, in your server's X session. Run the command (from your script):

mozilla -remote openURL('http://www.mysite.com')

This should open the URL up in the servers X session. Once that is done, take a screen shot with any of the available tools for X. We'll use xwd as an example:

xwd -frame -root -out myscreenshot.xwd

This will take a full screenshot of the X root window, which should have the browser window open at that URL.

After that, you may have to use ImageMagick or NetPBM to convert the file into something usable for the web.

Hope this helps, even if it just points you in the right direction.

9:14 pm on Nov 29, 2004 (gmt 0)

10+ Year Member


I have one question:

Will mozilla work under linux serwer, where is not graphic interface? Will it create screenshots?

2:30 am on Nov 30, 2004 (gmt 0)

10+ Year Member

At the risk of splitting the screenshot thread, there is an easy way to do this on a server with no graphics hardware: Xvfb. From the manpage:

Xvfb is an X server that can run on machines with no display hardware and no physical input devices. It emulates a dumb framebuffer using virtual memory.

In other words it pretends to be an X server and video card. Xvfb is suprisingly lightweight, memory wise. It doesn't require a full installation of X11 on the server, a window manager or to be run as root.

Here's how one might use it for screenshots.

Screenshot "server" script:
Xvfb :2 -screen 0 800x600x32 -fbdir /tmp &
DISPLAY=:2.0 mozilla -width 800 -height 600 &

Screenshooter script:
DISPLAY=:2.0 mozilla -remote "openURL(http://example.com)"
sleep 5 # give the page time to load
cp /tmp/Xvfb_screen0 /tmp/screenshot.xwd

Like mattx17, I'll leave converting a .xwd format image into something more useful as an exercise for the googler. Xvfb is an optional package in most Linux distributions, usually with names like xorg-x11-Xvfb or XFree86-Xvfb.

11:15 am on Dec 5, 2004 (gmt 0)

10+ Year Member

Thanks for reply! This is what i search for!
3:22 pm on Jan 2, 2005 (gmt 0)

10+ Year Member


I followed the Xvfb method (excellent idea!), using a 24-bit buffer and xwdtopnm ¦ pnmtojpeg/png/tif.

It all worked OK until I saw the final picture - it looks painfully deinterlaced and, well, wrong. I don't know much X as most of my experience is with headless servers - where should I start troubleshooting?

Thanks for your help!

[edited by: tedster at 6:07 pm (utc) on Jan. 2, 2005]