pixel_matcher 0.0.5 → 0.0.6
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 +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +17 -7
- data/images/generate.png +0 -0
- data/lib/pixel_matcher.rb +11 -1
- data/lib/pixel_matcher/diff_image.rb +49 -26
- data/lib/pixel_matcher/version.rb +1 -1
- metadata +3 -3
- data/images/screen_shot.jpeg +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9878d36f90fea82db8e1d5411b36b5d72d20d8353de7829ac7d90774ceb49396
|
4
|
+
data.tar.gz: f7bfb4d812e76a101ff2405af772c2d6706ff899c05d606984cb71c75440c181
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12546f60584e1c87744457e5eb8961cd5ceca0b27fefff265f1014c22cc9aee4c8559ce6023aabde4fdc30593774da2fecb981e3428939e9a34f6797dffe1f68
|
7
|
+
data.tar.gz: a2a76e6ffa2e0acb99434fbd336be3b70b4488ac9cf2903aba1af358bce04091209b2dc17d3eb6c3385483b25bacea0c047c09af31d30261785f8a1136b2c993
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
# PixelMatcher
|
2
|
+

|
3
|
+
[](https://badge.fury.io/rb/pixel_matcher)
|
4
|
+
[](https://travis-ci.org/ksk001100/pixel_matcher)
|
5
|
+

|
6
|
+

|
7
|
+

|
8
|
+
|
2
9
|
|
3
10
|
Library to compare images and generate difference image files
|
4
11
|
|
5
|
-

|
6
13
|
|
7
14
|
## Installation
|
8
15
|
|
@@ -28,18 +35,21 @@ require 'pixel_matcher'
|
|
28
35
|
# from rmagick image
|
29
36
|
require 'rmagick'
|
30
37
|
diff = PixelMatcher::DiffImage.new(Magick::Image.read('img1.png').first, Magick::Image.read('img2.png').first)
|
31
|
-
diff.
|
32
|
-
diff.
|
38
|
+
diff.export('diff.png') # or mode: :only
|
39
|
+
diff.export('gray_scale.png', mode: :gray_scale)
|
40
|
+
diff.export('compare.png', mode: :compare)
|
33
41
|
|
34
42
|
# from file path
|
35
43
|
diff = PixelMatcher::DiffImage.from_path('img1.png', 'img2.png')
|
36
|
-
diff.
|
37
|
-
diff.
|
44
|
+
diff.export('diff.png') # or mode: :only
|
45
|
+
diff.export('gray_scale.png', mode: :gray_scale)
|
46
|
+
diff.export('compare.png', mode: :compare)
|
38
47
|
|
39
48
|
# from blob
|
40
49
|
diff = PixelMatcher::DiffImage.from_blob(File.read('img1.png'), File.read('img2.png'))
|
41
|
-
diff.
|
42
|
-
diff.
|
50
|
+
diff.export('diff.png') # or mode: :only
|
51
|
+
diff.export('gray_scale.png', mode: :gray_scale)
|
52
|
+
diff.export('compare.png', mode: :compare)
|
43
53
|
```
|
44
54
|
|
45
55
|
|
data/images/generate.png
ADDED
Binary file
|
data/lib/pixel_matcher.rb
CHANGED
@@ -2,5 +2,15 @@ require "pixel_matcher/version"
|
|
2
2
|
require 'pixel_matcher/diff_image'
|
3
3
|
|
4
4
|
module PixelMatcher
|
5
|
-
class SizeMismatchError < StandardError
|
5
|
+
class SizeMismatchError < StandardError
|
6
|
+
def initialize(msg = 'Image size mismatch...')
|
7
|
+
super
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class ModeMismatchError < StandardError
|
12
|
+
def initialize(msg = 'Undefined mode...')
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
6
16
|
end
|
@@ -2,30 +2,50 @@ require 'rmagick'
|
|
2
2
|
|
3
3
|
module PixelMatcher
|
4
4
|
class DiffImage < Magick::Image
|
5
|
-
def initialize(
|
6
|
-
self.class.image_size_validate(
|
7
|
-
|
8
|
-
@
|
9
|
-
|
5
|
+
def initialize(original, changed)
|
6
|
+
self.class.image_size_validate!(original, changed)
|
7
|
+
|
8
|
+
@original = original
|
9
|
+
@changed = changed
|
10
|
+
super(@original.columns, @original.rows) { self.background_color = 'none' }
|
10
11
|
store_diff
|
11
12
|
end
|
12
13
|
|
13
14
|
def self.from_path(path1, path2)
|
14
|
-
|
15
|
-
|
16
|
-
new(
|
15
|
+
original = Magick::Image.read(path1).first
|
16
|
+
changed = Magick::Image.read(path2).first
|
17
|
+
new(original, changed)
|
17
18
|
end
|
18
19
|
|
19
20
|
def self.from_blob(bin1, bin2)
|
20
|
-
|
21
|
-
|
22
|
-
new(
|
21
|
+
original = Magick::Image.from_blob(bin1).first
|
22
|
+
changed = Magick::Image.from_blob(bin2).first
|
23
|
+
new(original, changed)
|
24
|
+
end
|
25
|
+
|
26
|
+
def export(output_path, mode: :only)
|
27
|
+
case mode
|
28
|
+
when :only then export_diff(output_path)
|
29
|
+
when :gray_scale then export_gray_scale(output_path)
|
30
|
+
when :compare then export_compare(output_path)
|
31
|
+
else self.class.mode_validate!
|
32
|
+
end
|
23
33
|
end
|
24
34
|
|
25
|
-
|
26
|
-
|
35
|
+
private
|
36
|
+
|
37
|
+
def store_diff
|
38
|
+
@original.columns.times do |i|
|
39
|
+
@original.rows.times do |j|
|
40
|
+
next if eq_pixel?(i, j)
|
41
|
+
|
42
|
+
store_pixels(i, j, 1, 1, [@original.pixel_color(i, j)])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
27
46
|
|
28
|
-
|
47
|
+
def eq_pixel?(column, row)
|
48
|
+
@original.pixel_color(column, row) == @changed.pixel_color(column, row)
|
29
49
|
end
|
30
50
|
|
31
51
|
def export_diff(output_path)
|
@@ -34,26 +54,29 @@ module PixelMatcher
|
|
34
54
|
end
|
35
55
|
|
36
56
|
def export_gray_scale(output_path)
|
37
|
-
gray_scale = @
|
38
|
-
gray_scale.composite!(self, Magick::CenterGravity, 0, 0, Magick::OverCompositeOp)
|
57
|
+
gray_scale = @original.clone.quantize(256, Magick::GRAYColorspace)
|
58
|
+
gray_scale.composite!(self, Magick::CenterGravity, 0, 0, Magick::OverCompositeOp)
|
39
59
|
gray_scale.write(output_path)
|
40
60
|
self
|
41
61
|
end
|
42
62
|
|
43
|
-
|
63
|
+
def export_compare(output_path)
|
64
|
+
@changed.compare_channel(@original, Magick::MeanSquaredErrorMetric)
|
65
|
+
.first
|
66
|
+
.write(output_path)
|
67
|
+
self
|
68
|
+
end
|
44
69
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
next if eq_pixel?(i, j)
|
70
|
+
class << self
|
71
|
+
def image_size_validate!(original, changed)
|
72
|
+
return if [original.columns, original.rows] == [changed.columns, changed.rows]
|
49
73
|
|
50
|
-
|
51
|
-
end
|
74
|
+
raise PixelMatcher::SizeMismatchError
|
52
75
|
end
|
53
|
-
end
|
54
76
|
|
55
|
-
|
56
|
-
|
77
|
+
def mode_validate!
|
78
|
+
raise PixelMatcher::ModeMismatchError
|
79
|
+
end
|
57
80
|
end
|
58
81
|
end
|
59
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixel_matcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksk001100
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|
@@ -114,7 +114,7 @@ files:
|
|
114
114
|
- bin/console
|
115
115
|
- bin/setup
|
116
116
|
- exe/pixel_matcher
|
117
|
-
- images/
|
117
|
+
- images/generate.png
|
118
118
|
- lib/pixel_matcher.rb
|
119
119
|
- lib/pixel_matcher/diff_image.rb
|
120
120
|
- lib/pixel_matcher/version.rb
|
data/images/screen_shot.jpeg
DELETED
Binary file
|