Skip to content

Instantly share code, notes, and snippets.

@grantmichaels
Forked from BinaryMuse/phantom.coffee
Created May 13, 2012 20:51
Show Gist options
  • Save grantmichaels/2690124 to your computer and use it in GitHub Desktop.
Save grantmichaels/2690124 to your computer and use it in GitHub Desktop.

Revisions

  1. @BinaryMuse BinaryMuse created this gist Apr 13, 2012.
    22 changes: 22 additions & 0 deletions phantom.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/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