Module: QrcodeHelper

Extended by:
QrcodeHelper
Included in:
QrcodeHelper
Defined in:
lib/rails_com/utils/qrcode_helper.rb

Constant Summary collapse

OPTIONS =
{
  resize_gte_to: false,
  resize_exactly_to: false,
  fill: 'white',
  color: 'black',
  size: 300,
  border_modules: 1,  # 二维码图片padding
  module_px_size: 6,
  file: nil
}

Instance Method Summary collapse

Instance Method Details

#code_file(url, **options) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/rails_com/utils/qrcode_helper.rb', line 16

def code_file(url, **options)
  png = code_png url, **options
  tmp = Tempfile.new
  tmp.binmode
  tmp.write png.to_s
  tmp.rewind
  tmp
end

#code_png(url, **options) ⇒ Object



30
31
32
33
# File 'lib/rails_com/utils/qrcode_helper.rb', line 30

def code_png(url, **options)
  qrcode = RQRCode::QRCode.new(url)
  qrcode.as_png **OPTIONS.merge(options)
end

#data_url(url, **options) ⇒ Object



25
26
27
28
# File 'lib/rails_com/utils/qrcode_helper.rb', line 25

def data_url(url, **options)
  png = code_png url, **options
  png.to_data_url
end