Capturing a manipulated web page with PhantomJS

PhantomJS is easy to compile in Ubuntu, uses QtWebKit to render pages, is controlled by Javascript and can output PNG. Here's a simple script to create a screenshot of a web page, with a tiny bit of DOM manipulation:

var url = 'http://www.guardian.co.uk/'
var output = 'snapshot.png'

switch (phantom.state.length){
    case 0:
        phantom.state = 'rasterize'
        phantom.viewportSize = { width: 1024, height: 768 }
        phantom.open(url)
    break;

    default:
        document.querySelectorAll("#guardian-logo img").item(0).setAttribute("src", "http://placekitten.com/344/52")
        phantom.sleep(1000)
        phantom.render(output)
        phantom.exit()
    break;
}