Class: Capybara::Screenshot::Diff::Drivers::ChunkyPNGDriver
- Inherits:
-
BaseDriver
- Object
- BaseDriver
- Capybara::Screenshot::Diff::Drivers::ChunkyPNGDriver
- 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
Instance Method Summary collapse
- #add_black_box(image, _region) ⇒ Object
- #crop(region, i) ⇒ Object
- #draw_rectangles(images, region, r, g, b, offset: 0) ⇒ Object
- #filter_image_with_median(_image) ⇒ Object
- #find_difference_region(comparison) ⇒ Object
- #from_file(filename_or_path) ⇒ Object
- #load_image_files(old_file_name, file_name) ⇒ Object
- #load_images(old_file_name, new_file_name) ⇒ Object
- #resize_image_to(image, new_width, new_height) ⇒ Object
- #same_pixels?(comparison) ⇒ Boolean
- #save_image_to(image, filename) ⇒ Object
Methods inherited from BaseDriver
#dimension, #height_for, #image_area_size, #same_dimension?, #width_for
Instance Method Details
#add_black_box(image, _region) ⇒ Object
31 32 33 |
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 31 def add_black_box(image, _region) image end |
#crop(region, i) ⇒ Object
39 40 41 |
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 39 def crop(region, i) i.crop(*region.to_top_left_corner_coordinates) end |
#draw_rectangles(images, region, r, g, b, offset: 0) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 59 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
27 28 29 |
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 27 def filter_image_with_median(_image) raise NotImplementedError end |
#find_difference_region(comparison) ⇒ Object
35 36 37 |
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 35 def find_difference_region(comparison) DifferenceRegionFinder.new(comparison, self).perform end |
#from_file(filename_or_path) ⇒ Object
43 44 45 |
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 43 def from_file(filename_or_path) ChunkyPNG::Image.from_file(filename_or_path.to_s) end |
#load_image_files(old_file_name, file_name) ⇒ Object
55 56 57 |
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 55 def load_image_files(old_file_name, file_name) [old_file_name.binread, file_name.binread] end |
#load_images(old_file_name, new_file_name) ⇒ Object
21 22 23 24 25 |
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 21 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
51 52 53 |
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 51 def resize_image_to(image, new_width, new_height) image.resample_bilinear(new_width, new_height) end |
#same_pixels?(comparison) ⇒ Boolean
71 72 73 |
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 71 def same_pixels?(comparison) comparison.new_image == comparison.base_image end |
#save_image_to(image, filename) ⇒ Object
47 48 49 |
# File 'lib/capybara/screenshot/diff/drivers/chunky_png_driver.rb', line 47 def save_image_to(image, filename) image.save(filename, :fast_rgba) end |