Class: Qrio::ImageLoader::PNGImageLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/qrio/image_loader/png_image_loader.rb

Class Method Summary collapse

Class Method Details

.load(filename) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/qrio/image_loader/png_image_loader.rb', line 4

def self.load(filename)
  image = ChunkyPNG::Image.from_file(filename)

  bits = image.pixels.map do |pixel|
    grayscale = ChunkyPNG::Color.to_grayscale(pixel)
    level = ChunkyPNG::Color.r(grayscale)
    level <= 126
  end

  Matrix.new(bits, image.width, image.height)
end