Class: Capybara::Screenshot::Diff::Drivers::ChunkyPNGDriver

Inherits:
BaseDriver
  • Object
show all
Includes:
ChunkyPNG::Color
Defined in:
lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb

Defined Under Namespace

Classes: DifferenceRegionFinder

Constant Summary

Constants inherited from BaseDriver

BaseDriver::PNG_EXTENSION

Instance Method Summary collapse

Methods inherited from BaseDriver

#dimension, #height_for, #image_area_size, #inscribed?, #same_dimension?, #width_for

Instance Method Details

#add_black_box(image, _region) ⇒ Object



26
27
28
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 26

def add_black_box(image, _region)
  image
end

#crop(region, i) ⇒ Object



34
35
36
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 34

def crop(region, i)
  i.crop(*region.to_top_left_corner_coordinates)
end

#draw_rectangles(images, region, r, g, b, offset: 0) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 54

def draw_rectangles(images, region, (r, g, b), offset: 0)
  border_color = ChunkyPNG::Color.rgb(r, g, b)
  border_shadow = ChunkyPNG::Color.rgba(r, g, b, 100)

  images.map do |image|
    new_img = image.dup
    new_img.rect(region.left - offset, region.top - offset, region.right + offset, region.bottom + offset, border_color)
    new_img.rect(region.left, region.top, region.right, region.bottom, border_shadow)
    new_img
  end
end

#filter_image_with_median(_image) ⇒ Object

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 22

def filter_image_with_median(_image)
  raise NotImplementedError
end

#find_difference_region(comparison) ⇒ Object



30
31
32
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 30

def find_difference_region(comparison)
  DifferenceRegionFinder.new(comparison, self).perform
end

#from_file(filename) ⇒ Object



38
39
40
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 38

def from_file(filename)
  ChunkyPNG::Image.from_file(filename.to_s)
end

#load_image_files(old_file_name, file_name) ⇒ Object



50
51
52
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 50

def load_image_files(old_file_name, file_name)
  [File.binread(old_file_name), File.binread(file_name)]
end

#load_images(old_file_name, new_file_name) ⇒ Object



16
17
18
19
20
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 16

def load_images(old_file_name, new_file_name)
  old_bytes, new_bytes = load_image_files(old_file_name, new_file_name)

  _load_images(old_bytes, new_bytes)
end

#resize_image_to(image, new_width, new_height) ⇒ Object



46
47
48
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 46

def resize_image_to(image, new_width, new_height)
  image.resample_bilinear(new_width, new_height)
end

#same_pixels?(comparison) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 66

def same_pixels?(comparison)
  comparison.new_image == comparison.base_image
end

#save_image_to(image, filename) ⇒ Object



42
43
44
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 42

def save_image_to(image, filename)
  image.save(filename)
end