Class: Imatcher::Image
- Inherits:
-
ChunkyPNG::Image
- Object
- ChunkyPNG::Image
- Imatcher::Image
- Includes:
- ColorMethods
- Defined in:
- lib/imatcher/image.rb
Overview
Extend ChunkyPNG::Image with some methods.
Instance Method Summary collapse
- #compare_each_pixel(image) ⇒ Object
- #each_pixel ⇒ Object
- #inspect ⇒ Object
- #render_bounds(left, bot, right, top) ⇒ Object
- #sizes_match?(image) ⇒ Boolean
- #to_grayscale ⇒ Object
- #with_alpha(value) ⇒ Object
Methods included from ColorMethods
Instance Method Details
#compare_each_pixel(image) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/imatcher/image.rb', line 16 def compare_each_pixel(image) height.times do |y| next if image.row(y) == row(y) row(y).each_with_index do |pixel, x| yield(pixel, 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 |
#inspect ⇒ Object
47 48 49 |
# File 'lib/imatcher/image.rb', line 47 def inspect "Image:#{object_id}<#{width}x#{height}>" end |
#render_bounds(left, bot, right, top) ⇒ Object
43 44 45 |
# File 'lib/imatcher/image.rb', line 43 def render_bounds(left, bot, right, top) rect(left, bot, right, top, rgb(255, 0, 0)) end |
#sizes_match?(image) ⇒ Boolean
39 40 41 |
# File 'lib/imatcher/image.rb', line 39 def sizes_match?(image) [width, height] == [image.width, image.height] end |
#to_grayscale ⇒ Object
25 26 27 28 29 30 |
# File 'lib/imatcher/image.rb', line 25 def to_grayscale each_pixel do |pixel, x, y| self[x, y] = grayscale(brightness(pixel).round) end self end |
#with_alpha(value) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/imatcher/image.rb', line 32 def with_alpha(value) each_pixel do |pixel, x, y| self[x, y] = rgba(r(pixel), g(pixel), b(pixel), value) end self end |