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
- #code_file(url, **options) ⇒ Object
- #code_png(url, **options) ⇒ Object
- #data_url(url, **options) ⇒ Object
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, **) png = code_png url, ** 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, **) qrcode = RQRCode::QRCode.new(url) qrcode.as_png **OPTIONS.merge() end |
#data_url(url, **options) ⇒ Object
25 26 27 28 |
# File 'lib/rails_com/utils/qrcode_helper.rb', line 25 def data_url(url, **) png = code_png url, ** png.to_data_url end |