Class: BigResources::DifferAnalyzeUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/big_resources/util/image/diff_analyze_util.rb

Class Method Summary collapse

Class Method Details

.image_diff_analyze(path, compare_path) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/big_resources/util/image/diff_analyze_util.rb', line 5

def self.image_diff_analyze(path,compare_path)

  images = [
    ChunkyPNG::Image.from_file(path),
    ChunkyPNG::Image.from_file(compare_path)
  ]

  diff = []
  #size compare
  return false unless images.first.height == images.last.height
  return false unless images.first.width == images.last.width

  #pixel compare
  images.first.height.times do | y |
    images.first.row(y).each_with_index do | pixel, x |
      diff << [x, y] unless pixel == images.last[x, y]
    end
  end
  diff.length.zero?
end