Mercurial > hg > nodescore
comparison rasterize.js @ 12:d2eda8be1fca
add phantomjs dependency for thumbnail preview generation
author | tzara <rc-web@kiben.net> |
---|---|
date | Sun, 08 Jul 2012 23:51:17 +0100 |
parents | |
children | ac9641ecf84f |
comparison
equal
deleted
inserted
replaced
11:0a8133490050 | 12:d2eda8be1fca |
---|---|
1 var page = require('webpage').create(), | |
2 system = require('system'), | |
3 address, output, size; | |
4 | |
5 page.clipRect = { top: 70, left: 0, width: 1280, height: 800 } | |
6 | |
7 if (system.args.length < 3 || system.args.length > 5) { | |
8 console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]'); | |
9 console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"'); | |
10 phantom.exit(1); | |
11 } else { | |
12 address = system.args[1]; | |
13 output = system.args[2]; | |
14 page.viewportSize = { width: 800, height: 800 }; | |
15 if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") { | |
16 size = system.args[3].split('*'); | |
17 page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' } | |
18 : { format: system.args[3], orientation: 'portrait', margin: '1cm' }; | |
19 } | |
20 if (system.args.length > 4) { | |
21 page.zoomFactor = system.args[4]; | |
22 } | |
23 page.open(address, function (status) { | |
24 if (status !== 'success') { | |
25 console.log('Unable to load the address!'); | |
26 } else { | |
27 window.setTimeout(function () { | |
28 page.render(output); | |
29 phantom.exit(); | |
30 }, 200); | |
31 } | |
32 }); | |
33 } |