https://github.com/whomwah/rqrcode
A Ruby library that encodes QR Codes
https://github.com/whomwah/rqrcode
Keywords
qrcode qrcode-generator ruby
Keywords from Contributors
crash-reporting activerecord rack sinatra mvc activejob rubygems error-handling feature-flag exceptions
Last synced: about 4 hours ago
JSON representation
Repository metadata
A Ruby library that encodes QR Codes
- Host: GitHub
- URL: https://github.com/whomwah/rqrcode
- Owner: whomwah
- License: mit
- Created: 2008-04-03T09:31:15.000Z (almost 18 years ago)
- Default Branch: main
- Last Pushed: 2025-11-25T15:42:13.000Z (about 2 months ago)
- Last Synced: 2025-12-29T10:50:21.302Z (13 days ago)
- Topics: qrcode, qrcode-generator, ruby
- Language: Ruby
- Homepage:
- Size: 538 KB
- Stars: 1,961
- Watchers: 27
- Forks: 239
- Open Issues: 0
- Releases: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
README.md
RQRCode
RQRCode is a library for creating and rendering QR codes into various formats. It has a simple interface with all the standard QR code options. It was adapted from the Javascript library by Kazuhiko Arase.
- QR code is trademarked by Denso Wave inc
- Minimum Ruby version is
>= 3.0.0
Installing
Add this line to your application's Gemfile:
gem "rqrcode", "~> 3.0"
or install manually:
gem install rqrcode
Basic usage example
require "rqrcode"
qr = RQRCode::QRCode.new("https://kyan.com")
puts qr.to_s
# to_s( dark: "x", light: " " ) # defaults
xxxxxxx xxxxxxx xxx xxxxxxx
x x x xxx xx x x
x xxx x xx x x xx x xxx x
x xxx x xx xx xx x xxx x
x xxx x x x xxx x xxx x
x x xxx x xx x x x x
...
Easy, but unlikely to be readable. For this you will need to use one of the many rendering options below.
Advanced Options
These are the various QR code generation options provided by the underlying rqrcode_core. You may actually only need this library if you don't need the various rendering options rqrcode provides, but just need the data structure.
Expects a string or array (for multi-segment encoding) to be parsed in, other args are optional
data - the string, QRSegment or array of Hashes (with data:, mode: keys) you wish to encode
size - the size (Integer) of the QR Code (defaults to smallest size needed to encode the data)
max_size - the max_size (Integer) of the QR Code (default RQRCodeCore::QRUtil.max_size)
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 QR Code (defaults to :alphanumeric or :byte_8bit, depending on the input data,
only used when data is a string):
* :number
* :alphanumeric
* :byte_8bit
Example
simple_qrcode = RQRCodeCore::QRCode.new("https://kyan.com", size: 2, level: :m, mode: :byte_8bit)
segment_qrcode = RQRCodeCore::QRCode.new([{ data: "foo", mode: :byte_8bit }])
multi_qrcode = RQRCodeCore::QRCode.new([
{ data: 'foo', mode: :byte_8bit },
{ data: 'BAR1', mode: :alphanumeric }
])
Render types
You probably want to output your QR code in a specific format. We make this easy by providing a bunch of formats to choose from below, each with their own set of options:
as_svg
The SVG renderer will produce a stand-alone SVG as a String
Options:
offset - Padding around the QR Code in pixels
(default 0)
offset_x - X Padding around the QR Code in pixels
(default offset)
offset_y - Y Padding around the QR Code in pixels
(default offset)
fill - Background color e.g "ffffff" or :white or :currentColor
(default none)
color - Foreground color e.g "000" or :black or :currentColor
(default "000")
module_size - The Pixel size of each module
(defaults 11)
shape_rendering - SVG Attribute: auto | optimizeSpeed | crispEdges | geometricPrecision
(defaults crispEdges)
standalone - Whether to make this a full SVG file, or only an svg to embed in other svg
(default true)
use_path - Use <path> to render SVG rather than <rect> to significantly reduce size.
This will become the default in future versions.
(default false)
viewbox - Replace the `svg.width` and `svg.height` attribute with `svg.viewBox` to
allow CSS scaling
(default false)
svg_attributes - A optional hash of custom <svg> attributes. Existing attributes will remain.
(default {})
Example
require "rqrcode"
qrcode = RQRCode::QRCode.new("http://github.com/")
# NOTE: showing with default options specified explicitly
svg = qrcode.as_svg(
color: "000",
shape_rendering: "crispEdges",
module_size: 11,
standalone: true,
use_path: true
)
as_png
The will produce a PNG using the ChunkyPNG gem. The result will be a ChunkyPNG::Image instance.
Options:
fill - Background <ChunkyPNG::Color>, defaults to 'white'. Use [] for multi args
color - Foreground <ChunkyPNG::Color>, defaults to 'black'. Use [] for multi args
When option :file is supplied you can use the following ChunkyPNG constraints:
color_mode - The color mode to use. Use one of the ChunkyPNG::COLOR_* constants.
(defaults to 'ChunkyPNG::COLOR_GRAYSCALE')
bit_depth - The bit depth to use. This option is only used for indexed images.
(defaults to 1 bit)
interlace - Whether to use interlacing (true or false).
(defaults to ChunkyPNG default)
compression - The compression level for Zlib. This can be a value between 0 and 9, or a
Zlib constant like Zlib::BEST_COMPRESSION
(defaults to ChunkyPNG default)
There are two sizing algorithms.
* Original that can result in blurry and hard to scan images
* Google's Chart API inspired sizing that resizes the module size to fit within the given image size.
The Google one will be used when no options are given or when the new size option is used.
*Google Sizing*
size - Total size of PNG in pixels. The module size is calculated so it fits.
(defaults to 120)
border_modules - Width of white border around the modules.
(defaults to 4).
-- DONT USE border_modules OPTION UNLESS YOU KNOW ABOUT THE QUIET ZONE NEEDS OF QR CODES --
*Original Sizing*
module_px_size - Image size, in pixels.
border - Border thickness, in pixels
It first creates an image where 1px = 1 module, then resizes.
Defaults to 120x120 pixels, customizable by option.
Example
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)

as_ansi
The ANSI renderer will produce as a string with ANSI color codes.
Options:
light - Foreground ANSI code
(default "\033[47m")
dark - Background ANSI code
(default "\033[40m")
fill_character - The written character
(default ' ')
quiet_zone_size - Padding around the edge
(default 4)
Example
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
)

API Documentation
http://www.rubydoc.info/gems/rqrcode
Tests
You can run the test suite using:
$ bundle install
$ rake # runs specs and standard:fix
$ rake spec # just runs the specs
or try the lib from the console with:
$ ./bin/console
Linting
The project uses standardrb and can be used with:
$ bundle install
$ rake standard # checks
$ rake standard:fix # fixes
Contributing
I am not currently accepting any new renderers as the current as_png, as_svg and as_ansi work for most cases. If you need something different from what's available, the rqrcode_core gem gives you access to all the QR Code information you will need so makes it simple to generate your own.
The motivation for the above is because the rendering side of this gem takes up the most time. It seems that many people want a slightly different version of a QR Code so supporting all the variations would be hard. The easiest way is to empower people to create their own versions which they can manage and share. This is what rqrcode_core does.
Any contribution PR's will be greatly accepted. It's important that they are well tested and backwards compatible.
- Fork the project
- Send a pull request
- Don't touch the .gemspec, I'll do that when I release a new version
Thanks D.
Authors
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.
Resources
- 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
Copyright
MIT License (http://www.opensource.org/licenses/mit-license.html)
Owner metadata
- Name: Duncan Robertson
- Login: whomwah
- Email: duncan@whomwah.com
- Kind: user
- Description: I do computing
- Website: http://whomwah.com
- Location: London, Uk
- Twitter:
- Company: @kyan
- Icon url: https://avatars.githubusercontent.com/u/2031?u=19988407e714b17f53fc8cea17cb624fdcc6c672&v=4
- Repositories: 70
- Last ynced at: 2025-11-28T12:13:29.917Z
- Profile URL: https://github.com/whomwah
GitHub Events
Total
- Create event: 14
- Commit comment event: 1
- Release event: 3
- Issues event: 6
- Watch event: 65
- Delete event: 9
- Issue comment event: 3
- Push event: 18
- Pull request review event: 2
- Pull request event: 16
- Fork event: 4
Last Year
- Create event: 14
- Commit comment event: 1
- Release event: 3
- Issues event: 4
- Watch event: 48
- Delete event: 9
- Issue comment event: 1
- Push event: 18
- Pull request review event: 2
- Pull request event: 16
- Fork event: 4
Committers metadata
Last synced: 2 days ago
Total Commits: 297
Total Committers: 45
Avg Commits per committer: 6.6
Development Distribution Score (DDS): 0.633
Commits in past year: 23
Committers in past year: 3
Avg Commits per committer in past year: 7.667
Development Distribution Score (DDS) in past year: 0.087
| Name | Commits | |
|---|---|---|
| Duncan Robertson | d****n@w****m | 109 |
| whomwah | w****h@7****8 | 36 |
| Gioele Barabucci | g****e@s****t | 28 |
| Darwin | d****t@m****e | 26 |
| Björn Blomqvist | b****t@s****e | 16 |
| Fabio Napoleoni | f****i@g****m | 13 |
| Tonči Damjanić | t****i@f****o | 11 |
| xn | xn@g****s | 10 |
| Christopher Lord | c****d@g****m | 5 |
| Yauhen Kharuzhy | j****r@g****m | 2 |
| Simon Schrape | s****p | 2 |
| Marcos Piccinini | x@n****m | 2 |
| Andreas Finger | a****r@x****m | 2 |
| Andy Brody | a****y@s****m | 2 |
| Jon Evans | j****e@f****m | 2 |
| Luis Mendes | l****s@g****m | 2 |
| Bèr Kessels | b****r@b****s | 1 |
| Bart Jedrocha | b****a@g****m | 1 |
| jlhonora | j****a@i****l | 1 |
| Matthew Croall | m****l@a****u | 1 |
| Martin McNickle | m****n@f****m | 1 |
| Christian Campbell | d****p@a****u | 1 |
| thiaguerd | m****l@t****o | 1 |
| nickgnd | n****d@g****m | 1 |
| ferdinand | f****o | 1 |
| Tore Darell | t****l@g****m | 1 |
| Thibaut Barrère | t****e@g****m | 1 |
| Takashi Kokubun | t****n@g****m | 1 |
| Simon Males | s****e@s****u | 1 |
| Sean Doig | s****g@g****m | 1 |
| and 15 more... | ||
Committer domains:
- bisnode.com: 1
- mowforth.com: 1
- jeremyevans.net: 1
- seib.nl: 1
- metaskills.net: 1
- omise.co: 1
- pocke.me: 1
- prognostikos.com: 1
- mikerogers.io: 1
- nickhammond.com: 1
- sime.net.au: 1
- thiago.pro: 1
- alumni.ufl.edu: 1
- floatapp.com: 1
- adelaidefringe.com.au: 1
- ing.puc.cl: 1
- berk.es: 1
- foraker.com: 1
- stripe.com: 1
- xing.com: 1
- nofxx.com: 1
- gotham.us: 1
- fivebyfive.co: 1
- seamless.se: 1
- marianna.se: 1
- svario.it: 1
- whomwah.com: 1
Issue and Pull Request metadata
Last synced: 2 days ago
Total issues: 48
Total pull requests: 84
Average time to close issues: 7 months
Average time to close pull requests: 6 months
Total issue authors: 45
Total pull request authors: 36
Average comments per issue: 2.73
Average comments per pull request: 0.85
Merged pull request: 59
Bot issues: 0
Bot pull requests: 0
Past year issues: 3
Past year pull requests: 13
Past year average time to close issues: about 2 months
Past year average time to close pull requests: about 2 hours
Past year issue authors: 3
Past year pull request authors: 2
Past year average comments per issue: 1.0
Past year average comments per pull request: 0.08
Past year merged pull request: 9
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- dmunozvenegas (2)
- dvodvo (2)
- barnaclebarnes (2)
- LWFlouisa (1)
- akhilesharora (1)
- dbackeus (1)
- rantler (1)
- carlosmedrano97 (1)
- Tioneb12 (1)
- colorfulberry (1)
- loust333 (1)
- greenbigfrog (1)
- krtschmr (1)
- olivierlacan (1)
- kannathasan-san (1)
Top Pull Request Authors
- whomwah (46)
- thiaguerd (2)
- mjy (2)
- akihikodaki (2)
- Jonakemon (1)
- 0r4cl3 (1)
- kerrizor (1)
- berkes (1)
- sugi (1)
- FlowerWrong (1)
- nickgnd (1)
- prognostikos (1)
- dasch (1)
- ghost (1)
- MattDahEpic (1)
Top Issue Labels
- view_layer (3)
Top Pull Request Labels
- view_layer (6)
- Ready for review (5)
- WIP (2)
Package metadata
- Total packages: 3
-
Total downloads:
- rubygems: 220,096,124 total
- Total docker downloads: 1,117,943,536
- Total dependent packages: 99 (may contain duplicates)
- Total dependent repositories: 4,128 (may contain duplicates)
- Total versions: 96
- Total maintainers: 1
gem.coop: rqrcode
rqrcode is a library for encoding QR Codes. The simple interface allows you to create QR Code data structures and then render them in the way you choose.
- Homepage: https://github.com/whomwah/rqrcode
- Documentation: http://www.rubydoc.info/gems/rqrcode/
- Licenses: MIT
- Latest release: 3.2.0 (published 2 days ago)
- Last Synced: 2026-01-09T09:10:38.402Z (1 day ago)
- Versions: 34
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 110,048,062 Total
- Docker Downloads: 558,971,768
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.1%
- Docker downloads count: 0.17%
- Downloads: 0.231%
- Maintainers (1)
rubygems.org: rqrcode
rqrcode is a library for encoding QR Codes. The simple interface allows you to create QR Code data structures and then render them in the way you choose.
- Homepage: https://github.com/whomwah/rqrcode
- Documentation: http://www.rubydoc.info/gems/rqrcode/
- Licenses: MIT
- Latest release: 3.2.0 (published 2 days ago)
- Last Synced: 2026-01-09T09:07:49.988Z (1 day ago)
- Versions: 34
- Dependent Packages: 99
- Dependent Repositories: 4,128
- Downloads: 110,048,062 Total
- Docker Downloads: 558,971,768
-
Rankings:
- Docker downloads count: 0.208%
- Downloads: 0.313%
- Dependent packages count: 0.347%
- Dependent repos count: 0.488%
- Average: 0.719%
- Stargazers count: 1.204%
- Forks count: 1.755%
- Maintainers (1)
proxy.golang.org: github.com/whomwah/rqrcode
- Homepage:
- Documentation: https://pkg.go.dev/github.com/whomwah/rqrcode#section-documentation
- Licenses: mit
- Latest release: v3.1.1+incompatible (published about 2 months ago)
- Last Synced: 2026-01-08T04:06:13.711Z (3 days ago)
- Versions: 28
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Dependent packages count: 5.497%
- Average: 5.681%
- Dependent repos count: 5.866%
Dependencies
- ast 2.4.2
- chunky_png 1.4.0
- diff-lcs 1.4.4
- parallel 1.21.0
- parser 3.1.0.0
- rainbow 3.0.0
- rake 13.0.3
- regexp_parser 2.2.0
- rexml 3.2.5
- rqrcode 2.1.1
- rqrcode_core 1.2.0
- rspec 3.10.0
- rspec-core 3.10.1
- rspec-expectations 3.10.1
- rspec-mocks 3.10.2
- rspec-support 3.10.2
- rubocop 1.24.1
- rubocop-ast 1.15.1
- rubocop-performance 1.13.1
- ruby-progressbar 1.11.0
- standard 1.6.0
- standardrb 1.0.0
- unicode-display_width 2.1.0
- bundler ~> 2.0 development
- rake ~> 13.0 development
- rspec ~> 3.5 development
- standardrb ~> 1.0 development
- chunky_png ~> 1.0
- rqrcode_core ~> 1.0
- actions/checkout v3 composite
- ruby/setup-ruby v1 composite
Score: 32.402347338282446