check filename for .png extension
[mkws-moved-to-github.git] / test / phantom / screenshot.js
1 var page = require('webpage').create(),
2     system = require('system');
3
4 var url = system.args[1] || 'http://www.indexdata.com/';
5 var file_png = system.args[2] || 'indexdata.png';
6 var timeout = system.args[5] ? system.args[5] : 0.2;
7
8 function usage (message) {
9     if (message) {
10         console.log(message + "\n");
11     }
12     console.log('Usage: screenshot.js <some URL> <file.png>');
13     phantom.exit();
14 }
15
16 if (system.args.length === 1) {
17     usage();
18 }
19
20 if (!file_png.match(/\.png$/)) {
21     usage("File name has no .png extension: '" + file_png + "'");
22 }
23
24
25 // page.zoomFactor = 1.0;
26 page.viewportSize = {
27     width: system.args[3] ? system.args[3] : 1200,
28     height: system.args[4] ? system.args[4] : 1000
29 };
30
31 page.clipRect = {
32     width: page.viewportSize.width,
33     height: page.viewportSize.height
34 };
35
36 page.open(url, function () {
37     // small delay
38     setTimeout(function () {
39         var ret = page.render(file_png);
40         phantom.exit();
41     }, timeout * 1000);
42 });
43
44 // EOF