Class: SnapDiff::Drivers::ChunkyPNGDriver
- Inherits:
-
Object
- Object
- SnapDiff::Drivers::ChunkyPNGDriver
- Includes:
- ChunkyPNG::Color, SnapDiff::Driver
- Defined in:
- lib/snap_diff/drivers/chunky_png_driver.rb
Defined Under Namespace
Classes: DifferenceRegionFinder
Constant Summary
Constants included from SnapDiff::Driver
SnapDiff::Driver::PNG_EXTENSION
Instance Method Summary collapse
- #add_black_box(image, _region) ⇒ Object
- #crop(region, i) ⇒ Object
- #draw_rectangles(images, region, r, g, b, offset: 0) ⇒ 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 included from SnapDiff::Driver
#dimension, #height_for, #image_area_size, included, #same_dimension?, #supports?, #width_for
Instance Method Details
#add_black_box(image, _region) ⇒ Object
26 27 28 |
# File 'lib/snap_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/snap_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/snap_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 |
#find_difference_region(comparison) ⇒ Object
30 31 32 |
# File 'lib/snap_diff/drivers/chunky_png_driver.rb', line 30 def find_difference_region(comparison) DifferenceRegionFinder.new(comparison, self).perform end |
#from_file(filename_or_path) ⇒ Object
38 39 40 |
# File 'lib/snap_diff/drivers/chunky_png_driver.rb', line 38 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
50 51 52 |
# File 'lib/snap_diff/drivers/chunky_png_driver.rb', line 50 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
20 21 22 23 24 |
# File 'lib/snap_diff/drivers/chunky_png_driver.rb', line 20 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/snap_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
66 67 68 |
# File 'lib/snap_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/snap_diff/drivers/chunky_png_driver.rb', line 42 def save_image_to(image, filename) image.save(filename, :fast_rgba) end |