#! /usr/bin/env phantomjs

var system = require('system')
  , webpage = require('webpage')
  , args = system.args

if (args.length != 5) {
  console.error('Required arguments: URL filename width height')
  phantom.exit(1)
}

var url = args[1]
  , filename = args[2]
  , width = args[3]
  , height = args[4]
  , page = webpage.create()

page.clipRect = {
  top: 0,
  left: 0,
  width: width,
  height: height
}

page.open(url, function() {
  page.render(filename)
  phantom.exit()
})
