Repository navigation
Draw QR codes as vectors, encoded in pure Ruby - #103
Merged
Merged
Conversation
qr_code encodes text in the smallest version that holds it at the level asked for, in numeric, alphanumeric or byte mode with UTF-8 announced by an ECI, and draws it as one path of rectangles and one fill. size counts the quiet zone, module_size sets one module; without at, the code is placed as an image is. Gamba's own API takes qr_code as a box. CI installs zbar, which reads every code the tests draw back from the rendered page. Assisted-by: Claude [Claude Code]
This was referenced Nov 13, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Invoices carry a payment QR code, but drawing one took another gem that makes a PNG, plus glue code to size it, and a bitmap scans worse once scaled. This is the first part of #74; the linear codes and DataMatrix follow in their own pull requests.
qr_codeencodes the text and draws it as vector rectangles: one path and one fill per symbol, with no dependency.:l,:m,:qand:h, and numeric, alphanumeric and byte modes; UTF-8 text is announced by an ECI. The smallest version that holds the text is chosen, and text too long for any version raises.sizeis the symbol's width with its four-module quiet zone, ormodule_sizesets one module (2 pt by default).quiet_zone: falseandcolorare options too.at, orpositionandvposition, and the cursor moves past the code.qr_codeis a box withsize,module_size,level,quiet_zone,colorandalign.Proof
test/qr_code_test.rbdraws 9 texts at each of the 4 levels and reads them back with zbar from the page rendered at 150 dpi: a URL, digits, the alphanumeric set, UTF-8 with CJK, an empty string, and random ASCII up to 400 characters. A version 28 code of 1500 bytes reads back too. Version choice matches the standard's capacities: 41 digits fit version 1-L and 42 do not, 7089 digits, 4296 alphanumerics and 2953 bytes fit version 40-L, 1273 bytes fit 40-H and 1274 raise. One code is one fill, at the expected corner and width. Encoding a 37-character URL takes 5.7 ms without JIT, most of it spent scoring the 8 masks; a full version 40 code takes 0.22 s.rake test: 1354 runs, 0 failures; RuboCop is clean.Generated by Claude Code