Created
June 19, 2012 21:40
-
-
Save javan/2956700 to your computer and use it in GitHub Desktop.
Create a screenshot of any URL using phantomjs (headless webkit)
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
// | |
// Example usage: phantomjs screenshot.js http://yahoo.com /tmp/yahoo.png | |
// | |
var system = require('system'); | |
var url = system.args[1]; | |
var filename = system.args[2]; | |
var page = new WebPage(); | |
page.open(url, function (status) { | |
page.render(filename); | |
console.log(filename) | |
phantom.exit(); | |
}); |
Yup. Built the 1.6 branch and that works.
page.open(url, function (status) {
console.log(page.renderBase64('PNG'))
phantom.exit();
});
So now I in a node server I can spawn this as a child process, listen to it's 'data' event, encode it back to binary and pipe it to the HTTP response. Obviously sending caching headers and caching on Cloudfront, Varnish, etc.
Voila!
@ismasan rad!
Hi,
I need to generate PDF instead of the image file. When i tried with 'PDF' to renderBase64, it doesn't work. Thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Aha! ariya/phantomjs@51ab11c
That might do it.