QRgen is a QR generation library fully written in Nim that only uses a small amount of pure-nim stdlib modules.
nim --version
>= 1.6.0
nimble install qrgen
- Supports all QR versions: from
1
to40
. - Supports all EC (Error Correction) levels:
L
,M
,Q
andH
. - Supports
numeric mode
,alphanumeric mode
andbyte mode
. - Supports printing a QR code on your terminal via standard output.
- Supports printing a QR code to SVG, with custom colors, using circles, embedding SVG logos etc.
- Supports rendering a QR code to pixie's
Image
, with the same features as SVG (but can embed more image formats).Image
can be exported to various formats, like PNG.
import QRgen
let myQR = newQR("https://github.com/aruZeta/QRgen")
myQR.printTerminal
myQR.printSvg
myQR.printSvg("#1d2021","#98971a")
"#1d2021"
sets the "light" or "background" color.
"#98971a"
sets the "dark" or "foreground" color.
myQR.printSvg("#1d2021","#98971a",60)
60
sets the alignment patterns' roundness to 60%.
myQR.printSvg("#1d2021","#98971a",100,100)
The first 100
sets the alignment patterns' roundness to 100%
while the second 100
sets the module's roundness to 100% too.
myQR.printSvg("#1d2021","#98971a",100,100,25)
The last 25
sets the module's separation to 25%.
Here we will need the highest EC level, for a better result (bigger logo):
let myQR = newQR("https://github.com/aruZeta/QRgen", ecLevel=qrECH)
myQR.printSvg("#1d2021","#98971a",100,100,25,svgImg=readFile("QRgen-logo.svg"))
svgImg
adds an SVG image embed in the center of generated
QR code, so we can pass it the contents of an SVG file, here a logo, and
the result as you can see is the actual QRgen logo.
Since the generated SVGs have css classes, we can do stuff like this:
2022-09-15.19-22-33.mp4
2022-09-15.19-24-14.mp4
Note: The PNG renderer is not exported with QRgen
since it depends on pixie
(check pixie here). To use it you will need
to add this import:
import QRgen/renderer
And obviously install and import pixie
too.
Note: renderImg
returns an Image
which to the save as let's say a PNG, you
will need to do:
let myQRImg = renderImg(...)
writeFile(myQRImg, "path/to/save/it.png")
You can check pixie to learn about more
formats you can save an Image
as.
myQR.renderImg
myQR.renderImg("#1d2021","#98971a")
"#1d2021"
sets the "light" or "background" color.
"#98971a"
sets the "dark" or "foreground" color.
myQR.renderImg("#1d2021","#98971a",60)
60
sets the alignment patterns' roundness to 60%.
myQR.renderImg("#1d2021","#98971a",100,100)
The first 100
sets the alignment patterns' roundness to 100%
while the second 100
sets the module's roundness to 100% too.
myQR.renderImg("#1d2021","#98971a",100,100,25)
The last 25
sets the module's separation to 25%.
Here we will need the highest EC level, for a better result (bigger logo):
let myQR = newQR("https://github.com/aruZeta/QRgen", ecLevel=qrECH)
myQR.renderImg("#1d2021","#98971a",100,100,25,img=readImage("QRgen-logo.png"))
img
embeds an Image
in the center of the generated QR code,
so we can use pixie's readImage
to read a PNG file, here a logo,
and the result as you can see is the actual QRgen logo.
Note that you can change the resolution of the generated image by setting
pixels
to a higher value, by default it's set to 512 pixels
(both width and height).
Check the docs to know more about the main API.
Check my simple terminal app's code, QRterm, which uses this library to generate QR codes from your terminal, and also it's logo generator.
Also check this repo's logo and its README images generator.
Distributed under the MIT License. See LICENSE
for more information.