image_compare 1.0.0.pre.dev → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a67b91873ee2ca3ec939803ef3ff7c7e116ce75e48d4643340aae67f48c59225
4
- data.tar.gz: 2795771468140989921e1ec9afffa2f9616f5363df7106e050ebcb36871659b0
3
+ metadata.gz: c9267d7bfce2137312246ee71c78be6123829c8d85306a6514fac4a5177fc1ed
4
+ data.tar.gz: 594a599fe736f30a8b92c28729e05db90c375ce9a3bf2c90056f5044a1151743
5
5
  SHA512:
6
- metadata.gz: 39a0d7d0bc330345bc4a9624bbbd721f7206db5d5c0d5900bfaa78bb0eec90dd9c03598d683c7f165a78549a8d311edaa7e206b5773abe96672479b25a322851
7
- data.tar.gz: 3fc93372828b8354867e63ac3e80cd2998fdd025ef9e3601a239d952f7ec0bfbdff3cd148bd03c4feb1a2c9cddf0be73c39da65ad55276639f3ac392886af1fa
6
+ metadata.gz: 980ef7ed37029399bb9fa7563b5f916bf466c44de53eecb433eed25841c5af37c4093cf59f4f1df45434c839b67e859a5d50294765e9d9c265bae45c54df6e2f
7
+ data.tar.gz: 17e44c8a2009a67e9a62ffc36d5cf68aa2e8c9c74d43ea4b34f090873c5461a10a023fb0802e5ea41cbd188c56b97dbda6fabc9384d67cdb1aee4899750e74fb
data/README.md CHANGED
@@ -36,6 +36,14 @@ Source images used in examples:
36
36
  <img src='https://raw.githubusercontent.com/instantink/image_compare/master/spec/fixtures/a.png' width='300' />
37
37
  <img src='https://raw.githubusercontent.com/instantink/image_compare/master/spec/fixtures/b.png' width='300' />
38
38
 
39
+ ### Color
40
+
41
+ Compare pixels, resulting score is a ratio of unequal pixels (with respect to provided tolerance).
42
+
43
+ Resulting diff contains version of the first image with different pixels highlighted in red and red bounding box.
44
+
45
+ <img src='https://raw.githubusercontent.com/instantink/image_compare/master/spec/fixtures/color_diff.png' width='300' />
46
+
39
47
  ### Base (RGB) mode
40
48
 
41
49
  Compare pixels by values, resulting score is a ratio of unequal pixels.
@@ -61,12 +69,17 @@ Resulting diff contains grayscale version of the first image with different pixe
61
69
  ## Usage
62
70
 
63
71
  ```ruby
64
- # create new matcher with default threshold equals to 0
65
- # and base (RGB) mode
72
+ # Create new matcher with default threshold equals to 0
73
+ # and base (Color) mode
66
74
  cmp = ImageCompare::Matcher.new
75
+ cmp.mode #=> ImageCompare::Modes::Color
76
+
77
+ # Create new matcher with default threshold equals to 0
78
+ # and base (RGB) mode
79
+ cmp = ImageCompare::Matcher.new mode: :rgb
67
80
  cmp.mode #=> ImageCompare::Modes::RGB
68
81
 
69
- # create matcher with specific threshold
82
+ # Create matcher with specific threshold
70
83
  cmp = ImageCompare::Matcher.new threshold: 0.05
71
84
  cmp.threshold #=> 0.05
72
85
 
@@ -74,7 +87,7 @@ cmp.threshold #=> 0.05
74
87
  cmp = ImageCompare::Matcher.new lower_threshold: 0.01
75
88
  cmp.lower_threshold #=> 0.01
76
89
 
77
- # create zero-tolerance grayscale matcher
90
+ # Create zero-tolerance grayscale matcher
78
91
  cmp = ImageCompare::Matcher.new mode: :grayscale, tolerance: 0
79
92
  cmp.mode #=> ImageCompare::Modes::Grayscale
80
93
 
@@ -103,9 +116,58 @@ You can exclude rectangle from comparing by passing `:exclude_rect` to `compare`
103
116
  E.g., if `path_1` and `path_2` contain images above
104
117
  ```ruby
105
118
  ImageCompare.compare(path_1, path_2, exclude_rect: [200, 150, 275, 200]).match? # => true
119
+
120
+ # or
121
+
122
+ cmp = ImageCompare::Matcher.new exclude_rect: [200, 150, 275, 200]
123
+ res = cmp.compare(path_1, path_2)
124
+ res #=> ImageCompare::Result
125
+ res.match? #=> true
126
+ res.score #=> 0.0
127
+
128
+ # Return diff image object
129
+ res.difference_image #=> ImageCompare::Image
130
+ res.difference_image.save(new_path)
106
131
  ```
107
132
  `[200, 150, 275, 200]` is array of two vertices of rectangle -- (200, 150) is left-top vertex and (275, 200) is right-bottom.
108
133
 
134
+ ### Cucumber + Capybara example
135
+ `support/env.rb`:
136
+ ```ruby
137
+ require 'image_compare'
138
+ ```
139
+
140
+ `support/capybara_extensions.rb`:
141
+ ```ruby
142
+ # frozen_string_literal: true
143
+
144
+ Capybara::Node::Element.class_eval do
145
+ def rect_area
146
+ rect_area = self.evaluate_script('this.getBoundingClientRect()')
147
+
148
+ [
149
+ rect_area['left'].to_f.round,
150
+ rect_area['top'].to_f.round,
151
+ rect_area['right'].to_f.round,
152
+ rect_area['bottom'].to_f.round
153
+ ]
154
+ rescue StandardError => e
155
+ raise "Error getting element rect area: #{e.inspect}!"
156
+ end
157
+ end
158
+ ```
159
+
160
+ `steps/my_step.rb`:
161
+ ```ruby
162
+ my_element = page.find('#my_element').rect_area
163
+
164
+ cmp = ImageCompare::Matcher.new exclude_rect: my_element.rect_area
165
+ res = cmp.compare(path_1, path_2)
166
+ res.difference_image.save(new_path)
167
+
168
+ expect(res.match?).to eq(true)
169
+ ```
170
+
109
171
  ## Including rectangle
110
172
 
111
173
  You can set bounds of comparing by passing `:include_rect` to `compare` with array similar to previous example
@@ -16,7 +16,7 @@ module ImageCompare
16
16
  attr_reader :mode
17
17
 
18
18
  def initialize(**options)
19
- mode_type = options.delete(:mode) || :rgb
19
+ mode_type = options.delete(:mode) || :color
20
20
  raise ArgumentError, "Undefined mode: #{mode_type}" unless MODES.key?(mode_type)
21
21
  @mode = Modes.const_get(MODES[mode_type]).new(**options)
22
22
  end
@@ -2,9 +2,9 @@
2
2
 
3
3
  module ImageCompare
4
4
  module Modes
5
- require 'image_compare/modes/rgb'
6
- require 'image_compare/modes/grayscale'
7
- require 'image_compare/modes/delta'
8
5
  require 'image_compare/modes/color'
6
+ require 'image_compare/modes/delta'
7
+ require 'image_compare/modes/grayscale'
8
+ require 'image_compare/modes/rgb'
9
9
  end
10
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ImageCompare
4
- VERSION = '1.0.0-dev'
4
+ VERSION = '1.0.0'
5
5
  end
data/lib/image_compare.rb CHANGED
@@ -6,8 +6,8 @@ module ImageCompare
6
6
  class SizesMismatchError < StandardError
7
7
  end
8
8
 
9
- require 'image_compare/matcher'
10
9
  require 'image_compare/color_methods'
10
+ require 'image_compare/matcher'
11
11
 
12
12
  def self.compare(path_a, path_b, **options)
13
13
  Matcher.new(**options).compare(path_a, path_b)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_compare
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.dev
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cristianofmc
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-03-24 00:00:00.000000000 Z
12
+ date: 2023-03-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chunky_png
@@ -99,9 +99,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
99
  version: 3.2.0
100
100
  required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">"
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
- version: 1.3.1
104
+ version: '0'
105
105
  requirements: []
106
106
  rubygems_version: 3.4.1
107
107
  signing_key: