Module: Qr4r

Defined in:
lib/qr4r.rb,
lib/qr4r/version.rb

Constant Summary collapse

SIZE_RESTRICTIONS =

params we use

pixel_size  - size of each dot, default = 3

params we pass to QRCode include :size and :level

size   - the size of the qrcode (default 4)
level  - the error correction level, can be:
   * Level :l 7%  of code can be restored
   * Level :m 15% of code can be restored
   * Level :q 25% of code can be restored
   * Level :h 30% of code can be restored

note: if size is not included and 4 appears to be too small for the included string, we’ll make it bigger

if you include size, we'll use it, which may lead to an error if the string is too long

Limitations are as follows:

size = 1, max string length = 7
size = 2, max string length = 14
size = 3, max string length = 24
size = 4, max string length = 34
size = 5, max string length = 44
size = 6, max string length = 58
size = 7, max string length = 64
size = 8, max string length = 84
size = 9, max string length = 98
size = 10, max string length = 119
[0, 7, 14, 24, 34, 44, 58, 64, 84, 98, 119]
VERSION =
'0.4.0'

Class Method Summary collapse

Class Method Details

.encode(str, outfile, *rest) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/qr4r.rb', line 30

def self.encode(str, outfile, *rest)
  opts = rest[0] if rest && rest.length > 0
  opts ||= {} 
  opts.merge!({:size => compute_size(str)}) unless opts[:size]
  opts.merge!({:pixel_size => 3}) unless opts[:pixel_size]
  qr, data = build_qr_code(str, opts)
  create_image(qr,data,outfile,opts)
end