6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/silkscreen.rb', line 6
def self.get_screenshot(url, options, driver)
window_width, window_height = options[:viewport].split('x').map { |x| x.to_i }
driver.manage.window.resize_to window_width, window_height
driver.navigate.to url
sleep options[:sleep]
img = driver.screenshot_as :png
if options[:full]
if options[:max_width] || options[:max_height]
canvas = ChunkyPNG::Image.from_blob img
canvas = resize_canvas(canvas, options[:max_width], options[:max_height])
img = canvas.to_s
end
else
canvas = ChunkyPNG::Image.from_blob img
canvas.crop! 0, 0, [window_width, canvas.width].min, [window_height, canvas.height].min
canvas = resize_canvas(canvas, options[:max_width], options[:max_height])
img = canvas.to_s
end
end
|