annotate 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
rev   line source
rc-web@12 1 var page = require('webpage').create(),
rc-web@12 2 system = require('system'),
rc-web@12 3 address, output, size;
rc-web@12 4
rc-web@12 5 page.clipRect = { top: 70, left: 0, width: 1280, height: 800 }
rc-web@12 6
rc-web@12 7 if (system.args.length < 3 || system.args.length > 5) {
rc-web@12 8 console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
rc-web@12 9 console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
rc-web@12 10 phantom.exit(1);
rc-web@12 11 } else {
rc-web@12 12 address = system.args[1];
rc-web@12 13 output = system.args[2];
rc-web@12 14 page.viewportSize = { width: 800, height: 800 };
rc-web@12 15 if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") {
rc-web@12 16 size = system.args[3].split('*');
rc-web@12 17 page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
rc-web@12 18 : { format: system.args[3], orientation: 'portrait', margin: '1cm' };
rc-web@12 19 }
rc-web@12 20 if (system.args.length > 4) {
rc-web@12 21 page.zoomFactor = system.args[4];
rc-web@12 22 }
rc-web@12 23 page.open(address, function (status) {
rc-web@12 24 if (status !== 'success') {
rc-web@12 25 console.log('Unable to load the address!');
rc-web@12 26 } else {
rc-web@12 27 window.setTimeout(function () {
rc-web@12 28 page.render(output);
rc-web@12 29 phantom.exit();
rc-web@12 30 }, 200);
rc-web@12 31 }
rc-web@12 32 });
rc-web@12 33 }