lib/element.rb in gridium-0.1.14 vs lib/element.rb in gridium-0.1.15
- old
+ new
@@ -245,18 +245,18 @@
end
def compare_element_screenshot(base_image_path)
#Returns TRUE if there are no differences, FALSE if there are
begin
- Log.debug("Doing Image Comparison...")
+ Log.debug("Loading Images for Comparison...")
images = [
ChunkyPNG::Image.from_file(base_image_path),
ChunkyPNG::Image.from_file(@element_screenshot)
]
#used to store image x,y diff
diff = []
- Log.debug("Loaded Images into array...")
+ Log.debug("Comparing Images...")
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
@@ -266,9 +266,10 @@
Log.debug("Pixels changed: #{(diff.length.to_f / images.first.pixels.length) * 100}%")
x, y = diff.map{|xy| xy[0]}, diff.map{|xy| xy[1]}
if x.any? && y.any?
+ Log.debug("Differences Detected! Writing Diff Image...")
name = self.name.gsub(' ', '_')
#timestamp = Time.now.strftime("%Y_%m_%d__%H_%M_%S")
element_screenshot_path = File.join($current_run_dir, "#{name}__diff_.png")
images.last.rect(x.min, y.min, x.max, y.max, ChunkyPNG::Color(0,255,0))
images.last.save(element_screenshot_path)
\ No newline at end of file