PhantomJS is a headless webkit browser, which means you can execute it from commandline and get it to do various tasks, such as headless website testing, screen capture, page automation and newwork monitoring.
In this blogpost i will show you how easy it is to take a screenshot of a website and save it to a preferred folder. I will use an Apple OSX computer for showing, but will easy be changed to ex. linux or Windows.
First of all you will need to start your terminal and download the package for OSX.
As an alternative you can install phantomjs with homebrew, but you will NOT get all the examples installed, and we need those examples for this to work.
Now you’re almost ready to go. Everything you will need is in the folder you’re in now. The phantomjs executable file is located in the bin/ folder, and a lot of examples is in the examples/ folder. I will not get into what every script can do, but only tell a bit about the examples/rasterize.js script.
To take a simple screenshot of an entire web page this command will do it for you:
bin/phantomjs examples/rasterize.js http://phantomjs.org/ ~/Desktop/phantomjs.png
And you will have a screenshot of the phantomjs.org website on your Desktop.
I have created a little script which will take a screenshot of whatever you have copied to your clipboard (with CMD+c), in this case it has to be a complete website url :o)
You will have to do these steps for using this script.
chmod +x screenshot.sh
Open the file in your preferred editor and change the variables
SCREENSHOT_PATH to match your filestructure, and save the file.
You will be able to execute the file and a screenshot will be saved, and finder will open the folder.
Or without an argument, and the latest entry in your clipboard will be used.