Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

QR png generator

View qr.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
require 'rubygems'
require 'rqrcode_png'
 
QR_CHAR_SIZE_VS_SIZE = [7, 14, 24, 34, 44, 58, 64, 84, 98, 119, 137, 155, 177, 194]
 
def minimum_qr_size_from_string(string)
QR_CHAR_SIZE_VS_SIZE.each_with_index do |size, index|
return (index + 1) if string.size < size
end
# If it's particularly big, we'll try and create codes until it accepts
i = QR_CHAR_SIZE_VS_SIZE.size
begin
i += 1
RQRCode::QRCode.new(string, :size => i)
return i
rescue RQRCode::QRCodeRunTimeError
retry
end
end
 
def qr_png(string)
size = minimum_qr_size_from_string(string)
qr = RQRCode::QRCode.new(string, :size => size, :level => :h )
png = qr.to_img
png.resize(200, 200).save("qr.png")
end
 
qr_png('Hello world')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.