heapsource / active_model_otp

Adds methods to set and authenticate against one time passwords (Two-Factor Authentication). Inspired in AM::SecurePassword
MIT License
773 stars 81 forks source link

undefined method `dark?' for #<RQRCode::QRCode:0x00005649dee622a0 #115

Closed rijotech closed 1 year ago

rijotech commented 1 year ago

Hi, I'm facing a problem trying to generate a Visual QR code I'm getting this error message. I'm using this Githubto generate the Visual QR Code.

undefined methoddark?' for #<RQRCode::QRCode:0x00005649dee622a0 @qrcode=QRCodeCore: @data='#', @error_correct_level=2, @version=4, @module_count=33>`

I noticed this is the part generating the error. data[y + 1][x + 1] = true if qr.dark?(x, y)

From here.

    def self.create(string, bgimg, options = {})
        options[:size] ||= 4
        options[:level] ||= :h
        options[:modified] ||= (options[:level] == :h ? 0.03 : 0)
        options[:bgcolor] ||= ChunkyPNG::Color(255, 255, 255)
        options[:dotpadding] ||= 0.25
        size = size(options[:size])
        qr = RQRCode::QRCode.new( string, :size => options[:size], :level => options[:level] )
        bw = (1.0 * bgimg.width / size).ceil
        bh = (1.0 * bgimg.height / size).ceil
        qrcode = ChunkyPNG::Image.new(bw * size, bh * size, ChunkyPNG::Color::TRANSPARENT)
        bb = bgimg.resample_bilinear(qrcode.width, qrcode.height)
        data = size.times.map { size.times.map { false } }
        qr.modules.each_index do |x|
            qr.modules.each_index do |y|
                data[y + 1][x + 1] = true if qr.dark?(x, y)
            end
        end