Created
January 26, 2013 17:53
-
-
Save ksiomelo/4643494 to your computer and use it in GitHub Desktop.
Library class for generating and saving QRCode images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#require 'action_controller' | |
require 'rqrcode' | |
require 'rqrcode-rails3/size_calculator.rb' | |
require 'rqrcode-rails3/renderers/svg.rb' | |
class LibQRCode | |
def self.generate_qrcode(text, options) | |
size = options[:size] | |
level = options[:level] || :h | |
qrcode = RQRCode::QRCode.new(text, :size => size, :level => level) | |
svg = RQRCode::Renderers::SVG::render(qrcode, options) | |
filename = SecureRandom.hex(12)+'.svg' # generates random unique name for the image file | |
directory = Rails.public_path + "/qrcodes" | |
File.open(File.join(directory, filename), 'w') do |f| | |
f.puts svg | |
end | |
return "qrcodes/"+filename | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment