Created
April 13, 2012 18:33
-
-
Save BinaryMuse/2378993 to your computer and use it in GitHub Desktop.
Take screenshots with Phantom.js from Node.js
This file contains hidden or 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
#!/usr/bin/env coffee | |
# Call the program with: coffee phantom.coffee http://url.to/screengrab | |
phantom = require 'phantom' # npm install phantom | |
child_process = require 'child_process' | |
url = process.argv[2] | |
createScreenshot = (page, filename) -> | |
page.render filename, -> | |
child_process.exec "open #{filename}" | |
process.exit() | |
phantom.create (ph) -> | |
ph.createPage (page) -> | |
page.set 'viewportSize', width: 1000, height: 1000 | |
page.set 'clipRect', top: 0, left: 0, width: 1000, height: 1000 | |
console.log "Opening #{url} ..." | |
page.open url, (status) -> | |
console.log "Rendering screenshot ..." | |
setTimeout (-> createScreenshot(page, 'output.png')), 1000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice. I had the same code, I added your sets for viewPortSize and a few other things.(sharing of a single Phantom instance)
https://gist.github.com/Rayjax/b793c561a54518bff845
Both JavaScript and Coffee versions