Class: ChromedriverScreenshot::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/chromedriver-screenshot/page.rb

Instance Method Summary collapse

Constructor Details

#initializePage

Returns a new instance of Page.



3
4
5
6
# File 'lib/chromedriver-screenshot/page.rb', line 3

def initialize
  bounds = row_boundaries
  @rows = Row.from_boundaries(bounds)
end

Instance Method Details

#full_screenshotObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/chromedriver-screenshot/page.rb', line 8

def full_screenshot
  rows = @rows.map { |row| row.screenshot }
  page_height = rows.inject(0) do |height, row|
    height += row.height
  end
  page_width = rows.first.width # assume all rows have same width
  screenshot = ChunkyPNG::Image.new(page_width, page_height)

  image_row = 0
  rows.each do |row|
    row_height = row.height - 1
    (0..row.height - 1).each do |row_y|
      new_image_row = row.row(row_y)
      screenshot.replace_row!(image_row + row_y, new_image_row)
    end
    image_row += row.height
  end

  Base64::encode64(screenshot.to_blob)
end