Class: Imatcher::Image
- Inherits:
-
ChunkyPNG::Image
- Object
- ChunkyPNG::Image
- Imatcher::Image
show all
- Includes:
- ColorMethods
- Defined in:
- lib/imatcher/image.rb
Overview
Extend ChunkyPNG::Image with some methods.
Instance Method Summary
collapse
#blue, #brightness, #green, #red
Instance Method Details
#bounding_rect ⇒ Object
56
57
58
|
# File 'lib/imatcher/image.rb', line 56
def bounding_rect
Rectangle.new(0, 0, width - 1, height - 1)
end
|
#compare_each_pixel(image, area: nil) ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/imatcher/image.rb', line 16
def compare_each_pixel(image, area: nil)
area = bounding_rect if area.nil?
(area.top..area.bot).each do |y|
range = (area.left..area.right)
next if image.row(y).slice(range) == row(y).slice(range)
(area.left..area.right).each do |x|
yield(self[x, y], image[x, y], x, y)
end
end
end
|
#each_pixel ⇒ Object
8
9
10
11
12
13
14
|
# File 'lib/imatcher/image.rb', line 8
def each_pixel
height.times do |y|
row(y).each_with_index do |pixel, x|
yield(pixel, x, y)
end
end
end
|
#highlight_rectangle(rect, color = :red) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/imatcher/image.rb', line 49
def highlight_rectangle(rect, color = :red)
fail ArgumentError, "Undefined color: #{color}" unless respond_to?(color)
return self if rect.nil?
rect(*rect.bounds, send(color))
self
end
|
#inspect ⇒ Object
45
46
47
|
# File 'lib/imatcher/image.rb', line 45
def inspect
"Image:#{object_id}<#{width}x#{height}>"
end
|
#sizes_match?(image) ⇒ Boolean
41
42
43
|
# File 'lib/imatcher/image.rb', line 41
def sizes_match?(image)
[width, height] == [image.width, image.height]
end
|
#to_grayscale ⇒ Object
27
28
29
30
31
32
|
# File 'lib/imatcher/image.rb', line 27
def to_grayscale
each_pixel do |pixel, x, y|
self[x, y] = grayscale(brightness(pixel).round)
end
self
end
|
#with_alpha(value) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/imatcher/image.rb', line 34
def with_alpha(value)
each_pixel do |pixel, x, y|
self[x, y] = rgba(r(pixel), g(pixel), b(pixel), value)
end
self
end
|