Skip to content
QR Encoding to PNG for Ruby http://www.rcode5.com
Ruby
Find file
Latest commit 1da811d @bunnymatic bunnymatic Update README.md
add note about examples dir
Failed to load latest commit information.
examples dump emacs temp files
lib refactor stuff
test refactor stuff
.gitignore adding examples (wip)
.rvmrc * change the way we handle opts
Gemfile rebundle
Gemfile.lock rebundle
README.md Update README.md
Rakefile * add ability to add :border
init.rb * added base files
qr4r.gemspec * reved contact info

README.md

QR Encoding via Ruby - with PNG output

Leveraging rqrcode and mojo_magick, we've built a very thin gem that generates QR codes in a png file

Include in your project

In your 'Gemfile', add

gem 'qr4r'

In your code, add

require 'qr4r'

NOTE: you'll need to have ImageMagick installed wherever you plan to run this. The gem depends on mojo_magick which uses ImageMagick commandline operations to build the final PNG image.

To use it:

Qr4r::encode(input_string, output_file_path, options)

input_string and output_file_path should be strings. Options should a list of hash options keyed by symbols. Possible options are:

  • :pixel_size - specify the size of each 'black' dot in the qrcode. Default = 3
  • :border - specify the number of pixels to use for a white border around the outside. Default = 0

To encode the string 'qr codes are the new hotness' like this:

require 'qr4r'
s = 'qr codes are the new hotness'
fname = s.gsub(/\s+/,"_") + ".qr.png"
Qr4r::encode(s, fname)

Make a bigger QRCode

s = 'big qr codes are the new hotness'
fname = s.gsub(/\s+/,"_") + ".qr.png"
Qr4r::encode(s, fname, :pixel_size => 5)

Add a fat border

s = 'big qr codes are the new hotness with a border'
fname = s.gsub(/\s+/,"_") + ".qr.png"
Qr4r::encode(s, fname, :border => 20)

You can also checkout the examples folder for a little sample commandline script.

NOTE: The current implementation or rQRCode (and therefore this wrapper library) supports encoding up to 119 characters. Beyond that, you'll need something a bit more sophisticated.

Wanna try it out?

Check out the Sinatra test app here: https://github.com/rcode5/qr4r_test_app

Versions/Changelog

0.4.0

  • Moved to new mojo_magick gem
  • no longer ruby 1.8.7 compatible
  • fixed issue with border coming out black

Authors

Original author: Jon Rogers at rcode5

Thanks to Duncan Robertson for writing rQRCode

Contributing

  • Fork the project
  • Write a test for your new feature/method
  • Send a pull request
  • Don't bump the version or modify the gemspec. I'll do that when I merge in your mods and release a new version.

Copyright

MIT Licence (http://www.opensource.org/licenses/mit-license.html)

Something went wrong with that request. Please try again.