Module: RQRCode

Extended by:
SizeCalculator
Defined in:
lib/rqrcode-rails3.rb,
lib/rqrcode-rails3/renderers/svg.rb,
lib/rqrcode-rails3/size_calculator.rb

Defined Under Namespace

Modules: Renderers, SizeCalculator

Constant Summary

Constants included from SizeCalculator

SizeCalculator::QR_CHAR_SIZE_VS_SIZE

Class Method Summary collapse

Methods included from SizeCalculator

minimum_qr_size_from_string

Class Method Details

.render_qrcode(string, format, options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rqrcode-rails3.rb', line 14

def render_qrcode(string, format, options)
  size   = options[:size]  || RQRCode.minimum_qr_size_from_string(string)
  level  = options[:level] || :h

  qrcode = RQRCode::QRCode.new(string, :size => size, :level => level)
  svg    = RQRCode::Renderers::SVG::render(qrcode, options)

  if format && format == :svg
    svg
  else
    image = MiniMagick::Image.read(svg) { |i| i.format "svg" }
    image.format format
    image.to_blob
  end
end