pixel_matcher 0.0.3 → 0.0.4

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: 6f74eb9515f4f4afbc889420fe889cea52a8f222eb07345a2a7d536744f81283
4
- data.tar.gz: 735290ba76f513abe2da41bd814e2459e0ca049d02cda7cd1097080911cf5164
3
+ metadata.gz: 4625b9a182bfacda310566d8369343374ebdf78aa370a8f9ce2f482f057b8464
4
+ data.tar.gz: f23bc22210b46b58739c298d4858293b248e82b6e67035763d1a246a0a13ad9e
5
5
  SHA512:
6
- metadata.gz: 16cd3a165ee5f880436485ecd11c764476a116a78bcc6f35a78c065fa89166519433c40f8ee4dcddfbe4c345a7bc9ad827dec38289e0d57e76f09e3f4dd86b89
7
- data.tar.gz: 138df0c70c5bd2bbfa42b805ee806c9a11474465598cd9589805038cbe469a5b54177b0b20f3d4a3d7efb73ab5944874aea002643729042e514fde2aa38b8215
6
+ metadata.gz: '08e08719ee337d8a72d2e45cbc7926b8e5d4d658116185ee0b6b711103917fb479f7525544b968fe82b0999c14eb669a0e0b209ca78542122231f3e68a491371'
7
+ data.tar.gz: 4a24ea644f3dde937b0b09ab3b2a9db99a21af3b63623c81d00d22657dccc4f46897924f331349e756f5f94cb37ceee17004f96ea3b61960f4226a10d02add5c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pixel_matcher (0.0.3)
4
+ pixel_matcher (0.0.4)
5
5
  rmagick (~> 4.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Library to compare images and generate difference image files
4
4
 
5
+ ![](images/screen_shot.jpeg)
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
Binary file
@@ -1,35 +1,42 @@
1
1
  require 'rmagick'
2
2
 
3
3
  module PixelMatcher
4
- class DiffImage
4
+ class DiffImage < Magick::Image
5
5
  def initialize(img1, img2)
6
+ self.class.image_size_validate(img1, img2)
6
7
  @img1 = img1
7
8
  @img2 = img2
8
- @gray_scale = @img1.clone.quantize(256, Magick::GRAYColorspace)
9
- @diff = Magick::Image.new(@img1.columns, @img1.rows)
9
+ super(@img1.columns, @img1.rows) { self.background_color = 'none' }
10
+ store_diff
10
11
  end
11
12
 
12
13
  def self.from_path(path1, path2)
13
14
  img1 = Magick::Image.read(path1).first
14
15
  img2 = Magick::Image.read(path2).first
15
- self.new(img1, img2)
16
+ new(img1, img2)
16
17
  end
17
18
 
18
19
  def self.from_blob(bin1, bin2)
19
20
  img1 = Magick::Image.from_blob(bin1).first
20
21
  img2 = Magick::Image.from_blob(bin2).first
21
- self.new(img1, img2)
22
+ new(img1, img2)
23
+ end
24
+
25
+ def self.image_size_validate(img1, img2)
26
+ return if [img1.columns, img1.rows] == [img2.columns, img2.rows]
27
+
28
+ raise PixelMatcher::SizeMismatchError, 'Image size mismatch'
22
29
  end
23
30
 
24
31
  def export_diff(output_path)
25
- store_diff
26
- @diff.write(output_path)
32
+ write(output_path)
27
33
  self
28
34
  end
29
35
 
30
36
  def export_gray_scale(output_path)
31
- store_gray_scale_diff
32
- @gray_scale.write(output_path)
37
+ gray_scale = @img1.clone.quantize(256, Magick::GRAYColorspace)
38
+ gray_scale.composite!(self, Magick::CenterGravity, 0, 0, Magick::OverCompositeOp);
39
+ gray_scale.write(output_path)
33
40
  self
34
41
  end
35
42
 
@@ -38,15 +45,7 @@ module PixelMatcher
38
45
  def store_diff
39
46
  @img1.columns.times do |i|
40
47
  @img1.rows.times do |j|
41
- @diff.store_pixels(i, j, 1, 1, [@img1.pixel_color(i, j)]) unless eq_pixel?(i, j)
42
- end
43
- end
44
- end
45
-
46
- def store_gray_scale_diff
47
- @img1.columns.times do |i|
48
- @img1.rows.times do |j|
49
- @gray_scale.store_pixels(i, j, 1, 1, [@img1.pixel_color(i, j)]) unless eq_pixel?(i, j)
48
+ store_pixels(i, j, 1, 1, [@img1.pixel_color(i, j)]) unless eq_pixel?(i, j)
50
49
  end
51
50
  end
52
51
  end
@@ -1,3 +1,3 @@
1
1
  module PixelMatcher
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/pixel_matcher.rb CHANGED
@@ -2,5 +2,5 @@ require "pixel_matcher/version"
2
2
  require 'pixel_matcher/diff_image'
3
3
 
4
4
  module PixelMatcher
5
- class Error < StandardError; end
5
+ class SizeMismatchError < StandardError; end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixel_matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksk001100
@@ -112,6 +112,7 @@ files:
112
112
  - Rakefile
113
113
  - bin/console
114
114
  - bin/setup
115
+ - images/screen_shot.jpeg
115
116
  - lib/pixel_matcher.rb
116
117
  - lib/pixel_matcher/diff_image.rb
117
118
  - lib/pixel_matcher/version.rb