Sha256: f59fe1b6883c687624a845bbde73d719e46ffc72438eced3a01777f8abaf59ca
Contents?: true
Size: 1.4 KB
Versions: 10
Compression:
Stored size: 1.4 KB
Contents
require 'rqrcode_png' module Fastlane class QRGenerator def initialize(data, dark_color = ::ChunkyPNG::Color::BLACK) @qr_code = RQRCode::QRCode.new(data, size: 10, level: :m) @dark_color = dark_color @light_color = ::ChunkyPNG::Color::WHITE @margin = 20 @image = ::ChunkyPNG::Image.new(2 * @margin + @qr_code.qrcode.module_count * 5, 2 * @margin + @qr_code.qrcode.module_count * 5, @light_color) end def generate(path) @qr_code.modules.each_index do |row| @qr_code.modules[row].each_index do |column| if @qr_code.modules[row][column] print_symbol(@dark_color, column, row, (column < 8 && row < 8) || (column < 8 && row >= @qr_code.qrcode.module_count - 8) || (column >= @qr_code.qrcode.module_count - 8 && row < 8)) else print_symbol(@light_color, column, row, (column < 8 && row < 8) || (column < 8 && row >= @qr_code.qrcode.module_count - 8) || (column >= @qr_code.qrcode.module_count - 8 && row < 8)) end end end @image.save(path) end private def print_symbol(color, column, row, interpolate) (0..4).each do |i| print_symbol_row(color, 5 * column + i, row, interpolate) end end def print_symbol_row(color, column, row, interpolate) (0..4).each do |i| @image[@margin + column, @margin + 5 * row + i] = color end end end end
Version data entries
10 entries across 10 versions & 1 rubygems