Command Line Program to Create Website Screenshots (On Linux)

Command line program to create website screenshots (on Linux)

A little more detail might be useful...

Start a firefox (or other browser) in an X session, either on your console or using a vncserver. You can use the --height and --width options to set the size of the window to full screen. Another firefox command can be used to set the URL being displayed in the first firefox window. Now you can grab the screen image with one of several commands, such as the "import" command from the Imagemagick package, or using gimp, or fbgrab, or xv.


# start a server with a specific DISPLAY
vncserver :11 -geometry 1024x768

# start firefox in this vnc session
firefox --display :11

# read URLs from a data file in a loop
while read url
# send URL to the firefox session
firefox --display :11 $url

# take a picture after waiting a bit for the load to finish
sleep 5
import -window root image$count.jpg

count=`expr $count + 1`
done < url_list.txt

# clean up when done
vncserver -kill :11

Generating Website screenshots on CentOS using PHP

There are various commandline utilities available. Most start one of the browser engines in headless X11 and take a screenshot then. A particular common one is khtml2png which can be used from php like this (not sure if there is a precompiled version for CentOS):

exec("khtml2png --width 800 --height 600 img.png");

A few more are listed here: Command line program to create website screenshots (on Linux)

Linux: launch window, capture screen

It sounds like you'll need to use the "virtual framebuffer" driver for the server, combined with the xwd, NetPBM, and cjpeg utilities.

I'm not sure about the particular configuration you'll need for the X server, but you will likely have to make sure the server you're using has the virtual framebuffer driver built into to. The virtual framebuffer driver is a display driver just like one you'd use to connect to an NVidia or ATI video card, except it's "output" is a chunk of memory that contains the pixels, not an LCD screen.

xwd is one of the standard X tools, that can create a X Window Dump. xwd can be told on the command line which window to dump. It outputs a funky "xwd" formatted stream to standard out.

The NetPBM utilities are a collection of command line tools that convert one image format to another. It includes one that converts xwdtoppm. PPM is a very basic, non-compressed format that is the intermediate format understood by most of the NetPBM tools.

cjpeg is part of the standard JPEG tools collection, and is probably installed if you also have NetPBM. cjpeg can take a stream of PPM bytes and emit a stream of JPEG bytes.

Through the magic of Unix scripting and pipes, you can string these utilities together to fire up the app with the window, call xwd, xwdtoppm, and cjpeg to dump the image to a file.

generate image (e.g. jpg) of a web page?

Try CutyCapt, a command-line utility. It uses Webkit for rendering and outputs in various formats (SVG, PNG, etc.).

Taking website screenshot, server-side, on a Linux rented server, free

PhantomJs is the solution

if(phantom.state.length === 0){
phantom.state = '0_home';'');
else if(phantom.state === '0_home'){
phantom.viewportSize = {width: 800, height: 600};

Take a full page screenshot with Firefox on the command-line

The Developer Toolbar GCLI and Shift+F2 shortcut were removed in Firefox version 60. To take a screenshot in 60 or newer:

  • press Ctrl+Shift+K to open the developer console (⌥ Option+⌘ Command+K on macOS)
  • type :screenshot or :screenshot --fullpage

Find out more regarding screenshots and other features

For Firefox versions < 60:

Press Shift+F2 or go to Tools > Web Developer > Developer Toolbar to open a command line. Write:


and press Enter in order to take a screenshot.

To fully answer the question, you can even save the whole page, not only the visible part of it:

screenshot --fullpage

And to copy the screenshot to clipboard, use --clipboard option:

screenshot --clipboard --fullpage

Firefox 18 changes the way arguments are passed to commands, you have to add "--" before them.

Firefox 88.0 has a new method for taking screenshots. If extensions.screenshots.disabled is set to false in about:config, you can right-click the screen and select Take Screenshot. There's also a screenshot menu button you can add to your menu via customization.

You can find some documentation and the full list of commands here.

PS. The screenshots are saved into the downloads directory by default.

webpage screenshot khtml2png alternatives

see this

with python

python /path/to/webkit2png

also you can do it with firefox !?

  firefox -savepng

Related Topics

Leave a reply