Module: Cosgrove::Phantomjs

Defined in:
lib/cosgrove/phantomjs.rb

Constant Summary collapse

PATH_TO_PHANTOM_SCRIPT =
"#{File.dirname(__FILE__)}/../../support/js/screencap.js"

Instance Method Summary collapse

Instance Method Details

#take_screencap(url, filename = nil, width = 64, height = 64) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/cosgrove/phantomjs.rb', line 8

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