Skip to content

Instantly share code, notes, and snippets.

@philogb
Created September 26, 2011 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philogb/1243805 to your computer and use it in GitHub Desktop.
Save philogb/1243805 to your computer and use it in GitHub Desktop.
var page = new WebPage(),
fs = require('fs'),
svg, output, size;
if (phantom.args.length < 4 || phantom.args.length > 4) {
console.log('Usage: svg2Image.js svg width height output');
phantom.exit();
} else {
svg = phantom.args[0];
width = phantom.args[1];
height = phantom.args[2];
output = phantom.args[3];
page.viewportSize = { width: 200, height: 200 };
page.content = '<html><head></head><body><svg width="800" height="800"><rect fill="#f00" width="200" height="200"></rect></svg></body></html>';
//page.content = '<html><body>hello world</body></html>';
console.log(page.content);
fs.write('something.html', page.content, 'w');
window.setTimeout(function() {
page.render(output);
window.setTimeout(function() {
phantom.exit();
}, 1000);
}, 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment