Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'chunky_png'
- require 'zbar'
- #Turns Colour PNG into 8bit BW Y800 string.
- # @param image [ChunckyPNG::Image]
- # @return [String] Y800 image, as a string
- def png_to_y800(image)
- y800 = ""
- (0...image.width).each do |w|
- (0...image.height).each do |h|
- v = image[h,w]
- y800 << (((ChunkyPNG::Color::r(v) * 0.21 +
- ChunkyPNG::Color::g(v) * 0.72 +
- ChunkyPNG::Color::b(v) * 0.07).round ) & 0xFF ).chr
- end
- end
- return y800
- end
- png_image = ChunkyPNG::Image.from_file(IMG)
- y800_image = png_to_y800(png_image)
- zbar_image = ZBar::Image.new
- zbar_image.set_data(ZBar::Format::Y800, y800_image, png_image.width, png_image.height)
- puts zbar_image.process[0].data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement