Sha256: d3c17a95c7c7b598f28d3324d0a1bbd3af95e63146b8a39df3e20a473aefc305

Contents?: true

Size: 582 Bytes

Versions: 32

Compression:

Stored size: 582 Bytes

Contents

require 'phantomjs'

# See: http://www.thegreatcodeadventure.com/screen-capture-in-rails-with-phantomjs/
module Cosgrove
  module Phantomjs
    PATH_TO_PHANTOM_SCRIPT = "#{File.dirname(__FILE__)}/../../support/js/screencap.js"
    
    def take_screencap(url, filename = nil, width = 64, height = 64)
      target_path = Digest::MD5.hexdigest(filename || url.parameterize)
      target_path += '.png'
      
      Dir.chdir('/tmp')
      system "phantomjs #{PATH_TO_PHANTOM_SCRIPT} \"#{url}\" #{target_path} #{width} #{height}"
      
      File.open(target_path)
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
cosgrove-0.0.1rc12 lib/cosgrove/phantomjs.rb
cosgrove-0.0.1rc11 lib/cosgrove/phantomjs.rb
cosgrove-0.0.1rc10 lib/cosgrove/phantomjs.rb
cosgrove-0.0.1rc9 lib/cosgrove/phantomjs.rb
cosgrove-0.0.1rc8 lib/cosgrove/phantomjs.rb
cosgrove-0.0.1rc7 lib/cosgrove/phantomjs.rb
cosgrove-0.0.1rc6 lib/cosgrove/phantomjs.rb
cosgrove-0.0.1rc5 lib/cosgrove/phantomjs.rb
cosgrove-0.0.1rc4 lib/cosgrove/phantomjs.rb
cosgrove-0.0.1rc3 lib/cosgrove/phantomjs.rb
cosgrove-0.0.1rc2 lib/cosgrove/phantomjs.rb
cosgrove-0.0.1rc1 lib/cosgrove/phantomjs.rb