- QR code is trademarked by Denso Wave inc
- Minimum Ruby version is
< 1.0.0please use this README
Add this line to your application's
or install manually:
gem install rqrcode
Basic usage example
require 'rqrcode' qr = RQRCode::QRCode.new('http://github.com') result = '' qr.qrcode.modules.each do |row| row.each do |col| result << (col ? 'X' : 'O') end result << "\n" end puts result
These are the various QR Code generation options provided by rqrqcode_core.
string - the string you wish to encode 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 (default :h) mode - the mode of the qrcode (defaults to alphanumeric or byte_8bit, depending on the input data): * :number * :alphanumeric * :byte_8bit * :kanji
qrcode = RQRCodeCore::QRCode.new('hello world', size: 1, level: :m, mode: :alphanumeric)
You can output your QR code in various forms. These are detailed below:
The SVG renderer will produce a stand-alone SVG as a
require 'rqrcode' qrcode = RQRCode::QRCode.new("http://github.com/") # NOTE: showing with default options specified explicitly svg = qrcode.as_svg( offset: 0, color: '000', shape_rendering: 'crispEdges', module_size: 6, standalone: true )
The ANSI renderer will produce as a string with ANSI color codes.
require 'rqrcode' qrcode = RQRCode::QRCode.new("http://github.com/") # NOTE: showing with default options specified explicitly svg = qrcode.as_ansi( light: "\033[47m", dark: "\033[40m", fill_character: ' ', quiet_zone_size: 4 )
The library can produce a PNG. Result will be a
require 'rqrcode' qrcode = RQRCode::QRCode.new("http://github.com/") # NOTE: showing with default options specified explicitly png = qrcode.as_png( bit_depth: 1, border_modules: 4, color_mode: ChunkyPNG::COLOR_GRAYSCALE, color: 'black', file: nil, fill: 'white', module_px_size: 6, resize_exactly_to: false, resize_gte_to: false, size: 120 ) IO.binwrite("/tmp/github-qrcode.png", png.to_s)
On the console ( just because you can )
require 'rqrcode' qr = RQRCode::QRCode.new('http://kyan.com', size: 4, level: :h) puts qr.to_s
xxxxxxx x x xxx xxxxxxx x x xxxxx x x x x x xxx x x x x x xxx x x xxx x xxx x xxx x xxx x x xxx x xxx x x x x xxx x ... etc
You can run the test suite using:
$ ./bin/setup $ bundle exec rspec
or try the lib from the console with:
as_ansi etc etc renderings of a QR Code will eventually (when I can get round to it) be moved into their own gems so they can be managed independently by people in their own repos -- ideally -- who are interested in this kind of thing. This will leave me to look after
rqrcode_core gem which I do have time for.
So for example if you only required a
png rendering of a QR Code, you could simply use the gem
rqrcode_png. This eventually means that the
rqrcode gem will just become a lightweight gem that pulls in all the various rendering and TBH will likely be depreciated.
The motivation behind all this is because the rendering side of this gem takes up the most time. Everyone wants a slightly different version of a QR Code and it's impossible to support everyone. The easiest way is to empower people to create their own which they can manage.
The work shouldn't impact any current users of the gem. What this does mean though is that any contribution PR's should only be bug fixes rather than new functionality. Thanks.
- Fork the project
- Send a pull request
- Don't touch the .gemspec, I'll do that when I release a new version
Original RQRCode author: Duncan Robertson
A massive thanks to all the contributors of the library over the years. It wouldn't exist if it wasn't for you all.
Oh, and thanks to my bosses at https://kyan.com for giving me time to maintain this project.
- wikipedia:: http://en.wikipedia.org/wiki/QR_Code
- Denso-Wave website:: http://www.denso-wave.com/qrcode/index-e.html
- kaywa:: http://qrcode.kaywa.com
MIT License (http://www.opensource.org/licenses/mit-license.html)