Dejan Levec

Screenshot of Web Page on Linux Server

[b]How to make a screenshot of web page on Linux server?[/b]

In this tutorial I will tell how to setup a server with Debian Lenny operating system to add capability for taking screenshot pictures of a web page you want.
[center][url=/media/techsiteblog/uploads/tech.jpg][img]/media/techsiteblog/uploads/tech-300×225.jpg[/img][/url][/center]

[b]Steps:[/b]
1. Login to server through SSH as root user.
2. Install vnc server, web browser and GUI with following command:
[quote]apt-get install tightvncserver xfonts-base xfce4 iceweasel imagemagick[/quote]
It’s about 160MB to download and installation should take a few minutes.
3. Start VNC server by typing:
[quote]vncserver :1 -geometry 1024×768 -depth 24[/quote]
4. Server should be running now, and you can stop some of probably unwanted services:
[quote]killall x-session-manager ssh-agent xftaskbar4 xfdesktop xfce4-panel[/quote]
5. Now connect to the VNC server from your desktop machine and remove unnecessary panels, configure Iceweasel web browser.

If you’re using iptables firewall you’ll need to add following rule to allow access to VNC server:
[quote]-A INPUT -p tcp -m tcp –dport 5901 -j ACCEPT[/quote]
6. That’s it. Now you have a machine capable of taking screenshots of websites.

[b]How to take a screenshot?[/b]

Create a shell file (for example screenshot.sh) with following script which starts the web browser, loads a page, takes a picture and closes the web browser.
[quote]#!/bin/bash
export DISPLAY=\":1\"
/usr/bin/iceweasel –display :1 \"$1\" > /dev/null 2> /dev/null &
/bin/sleep 10
/usr/bin/import -window root -display :1 \"$2\"
killall -9 /usr/lib/iceweasel/firefox-bin[/quote]
This script can be called like this:
[quote]./screenshot.sh http://www.google.com /var/www/picture_path.jpg[/quote]
Now you can take picture of any page you’d like with this simple command. It takes about 11 seconds to take 1 screenshot (script needs to sleep for about 10 seconds so that the page can load in web browser – you can change that time but is not recommended to set it bellow 5 seconds because most of the pages won’t load that quickly).

When you’re finished with taking screenshots you can kill vncserver with following command:
[quote]vncserver -kill :1[/quote]
That’s it for this tutorial. Additionally you can write PHP script which calls screenshots.sh and automatically crop picture to remove sliders and other unwanted elements on it.

Leave a Reply

Your email address will not be published. Required fields are marked *