class Imatcher::Image

Extend ChunkyPNG::Image with some methods.

Public Instance Methods

bounding_rect() click to toggle source
# 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) { |self, image, x, y| ... } click to toggle source
# 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() { |pixel, x, y| ... } click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/imatcher/image.rb, line 45
def inspect
  "Image:#{object_id}<#{width}x#{height}>"
end
sizes_match?(image) click to toggle source
# File lib/imatcher/image.rb, line 41
def sizes_match?(image)
  [width, height] == [image.width, image.height]
end
to_grayscale() click to toggle source
# 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) click to toggle source
# 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