annotate rasterize.js @ 101:52e44ee1c791 tip master

enabled all scores in autostart script
author Rob Canning <rc@kiben.net>
date Tue, 21 Apr 2015 16:20:57 +0100
parents 7f0485e0d0ff
children
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@26 5 top = system.args[3];
rc-web@26 6
rc-web@43 7 page.clipRect = { top: top, left: 0, width: 1000, height: 330 }
rc-web@12 8
rc-web@12 9 if (system.args.length < 3 || system.args.length > 5) {
rc-web@12 10 console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
rc-web@12 11 console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
rc-web@12 12 phantom.exit(1);
rc-web@12 13 } else {
rc-web@12 14 address = system.args[1];
rc-web@12 15 output = system.args[2];
rc-web@26 16
rc-web@26 17
rc-web@43 18 page.viewportSize = { width: 1000, height: 330 };
rc-web@26 19 if (system.args.length > 4 && system.args[2].substr(-4) === ".pdf") {
rc-web@26 20 size = system.args[4].split('*');
rc-web@12 21 page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
rc-web@32 22 : { format: system.args[3], orientation: 'portrait', margin: '0cm' };
rc-web@12 23 }
rc-web@26 24 if (system.args.length > 5) {
rc-web@26 25 page.zoomFactor = system.args[5];
rc-web@12 26 }
rc-web@12 27 page.open(address, function (status) {
rc-web@12 28 if (status !== 'success') {
rc-web@12 29 console.log('Unable to load the address!');
rc-web@12 30 } else {
rc-web@12 31 window.setTimeout(function () {
rc-web@12 32 page.render(output);
rc-web@12 33 phantom.exit();
rc-web@12 34 }, 200);
rc-web@12 35 }
rc-web@12 36 });
rc-web@12 37 }