Created
September 29, 2017 12:05
-
-
Save lotas/7299a4612cb346592e6615efc5f475cf to your computer and use it in GitHub Desktop.
render.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global phantom, console */ | |
'use strict'; | |
var system = require('system'); | |
if (system.args.length < 3) { | |
console.error('I need more arguments: render-image [template] [outputFilename]'); | |
phantom.exit(1); | |
} | |
var page = require('webpage').create(); | |
var template = system.args[1]; | |
var fileName = system.args[2]; | |
page.viewportSize = { | |
width: 1024, | |
height: 768 | |
}; | |
page.open(template); | |
page.onLoadFinished = renderImage; | |
page.onCallback = renderImage; | |
var cbCount = 0; | |
function renderImage(data) { | |
cbCount++; | |
if (cbCount >= 2) { | |
page.render(fileName); | |
console.log('Image generated'); | |
phantom.exit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment