Class: ImgDiff

Inherits:
Thor::Group
  • Object
show all
Defined in:
lib/imgdiff.rb

Instance Method Summary collapse

Instance Method Details

#execObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/imgdiff.rb', line 12

def exec
  original,target,output = original_image_path,target_image_path,composite_image_path

  # when output file name is not given, make it from file names with timestamp
  output = File.dirname(original) + '/' + File.basename(original,".*") + "_" + \
           File.basename(target,".*") + "_diff_" + \
           Time.now.strftime("%Y%m%d%H%M%S") + File.extname(original) if output.nil?

  raise "ERROR: #{original} is not found" unless File.exist?(original)
  raise "ERROR: #{target} is not found" unless File.exist?(target)

  original = Magick::Image.read(original).first
  target = Magick::Image.read(target).first

  if original.difference(target) == [0.0,0.0,0.0]
    puts 'There is no diff between the files'
    return true
  end

  original.composite(target,Magick::CenterGravity,Magick::DifferenceCompositeOp).write(output)
end