Class: PixelMatcher::DiffImage

Inherits:
Magick::Image
  • Object
show all
Defined in:
lib/pixel_matcher/diff_image.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original, changed) ⇒ DiffImage

Returns a new instance of DiffImage.



5
6
7
8
9
10
11
12
# File 'lib/pixel_matcher/diff_image.rb', line 5

def initialize(original, changed)
  self.class.image_size_validate!(original, changed)

  @original = original
  @changed = changed
  super(@original.columns, @original.rows) { self.background_color = 'none' }
  store_diff
end

Class Method Details

.from_blob(bin1, bin2) ⇒ Object



20
21
22
23
24
# File 'lib/pixel_matcher/diff_image.rb', line 20

def self.from_blob(bin1, bin2)
  original = Magick::Image.from_blob(bin1).first
  changed = Magick::Image.from_blob(bin2).first
  new(original, changed)
end

.from_path(path1, path2) ⇒ Object



14
15
16
17
18
# File 'lib/pixel_matcher/diff_image.rb', line 14

def self.from_path(path1, path2)
  original = Magick::Image.read(path1).first
  changed = Magick::Image.read(path2).first
  new(original, changed)
end

.image_size_validate!(original, changed) ⇒ Object



71
72
73
74
75
# File 'lib/pixel_matcher/diff_image.rb', line 71

def image_size_validate!(original, changed)
  return if [original.columns, original.rows] == [changed.columns, changed.rows]

  raise PixelMatcher::SizeMismatchError
end

.mode_validate!Object



77
78
79
# File 'lib/pixel_matcher/diff_image.rb', line 77

def mode_validate!
  raise PixelMatcher::ModeMismatchError
end

Instance Method Details

#export(output_path, mode: :only) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/pixel_matcher/diff_image.rb', line 26

def export(output_path, mode: :only)
  case mode
  when :only then export_diff(output_path)
  when :gray_scale then export_gray_scale(output_path)
  when :compare then export_compare(output_path)
  else self.class.mode_validate!
  end
end