QRCoders.jl Documentation
Module that can create QR codes as data or images using qrcode
or exportqrcode
.
Creating QR codes
QRCoders.qrcode
— Functionqrcode( message::AbstractString
; eclevel::ErrCorrLevel = Medium()
, version::Int = 0
, mode::Mode = Numeric()
, mask::Int = -1
, width::Int=0)
Create a BitArray{2}
with the encoded message
, with true
(1
) for the black areas and false
(0
) as the white ones.
The error correction level eclevel
can be picked from four values: Low()
(7% of missing data can be restored), Medium()
(15%), Quartile()
(25%) or High()
(30%). Higher levels make denser QR codes.
The version of the QR code can be picked from 1 to 40. If the assigned version is too small to contain the message, the first available version is used.
The encoding mode mode
can be picked from five values: Numeric()
, Alphanumeric()
, Byte()
, Kanji()
or UTF8()
. If the assigned mode
is nothing
or failed to contain the message, the mode is automatically picked.
The mask pattern mask
can be picked from 0 to 7. If the assigned mask
is nothing
, the mask pattern will picked by the penalty rules.
qrcode(code::QRCode)
Create a QR code matrix by the QRCode
object.
Note: It would raise an error if failed to use the specified mode
or
version`.
QRCoders.exportqrcode
— Functionexportqrcode( message::AbstractString
, path::AbstractString = "qrcode.png"
; eclevel::ErrCorrLevel = Medium()
, version::Int = 0
, mode::Mode = nothing
, width::int = 4
, pixels::Int = 160)
Create an image with the encoded message
of approximate size pixels x pixels
.
The error correction level eclevel
can be picked from four values: Low()
(7% of missing data can be restored), Medium()
(15%), Quartile()
(25%) or High()
(30%). Higher levels make denser QR codes.
The version of the QR code can be picked from 1 to 40. If the assigned version is too small to contain the message, the first available version is used.
The encoding mode mode
can be picked from four values: Numeric()
, Alphanumeric()
, Byte()
, Kanji()
or UTF8()
. If the assigned mode
is nothing
or failed to contain the message, the mode is automatically picked.
The mask pattern mask
can be picked from 0 to 7. If the assigned mask
is nothing
, the mask pattern will picked by the penalty rules.
exportqrcode( code::QRCode
, path::AbstractString = "qrcode.png"
; pixels::Int = 160)
Create an image with the encoded message
of approximate size targetsize
.
exportqrcode( codes::AbstractVector{QRCode}
, path::AbstractString = "qrcode.gif"
; pixels::Int = 160
, fps::Int = 2)
Create an animated gif with codes
of approximate size targetsize
.
The frame rate fps
is the number of frames per second.
Note: The codes
should have the same size while the other properties can be different.
exportqrcode( msgs::AbstractVector{<:AbstractString}
, path::AbstractString = "qrcode.gif"
; eclevel::ErrCorrLevel = Medium()
, version::Int = 0
, mode::Mode = Numeric()
, mask::Int = -1
, width::Int = 4
, targetsize::Int = 5
, pixels::Int = 160
, fps::Int = 2)
Create an animated gif with msgs
of approximate size pixels x pixels
.
The frame rate fps
is the number of frames per second.
QRCoders.QRCode
— TypeQRCode
A type that represents a QR code.
Fields
version::Int
: version of the QR codemode::Mode
: encoding mode of the QR codeeclevel::ErrCorrLevel
: error correction level of the QR codemask::Int
: mask pattern of the QR codemessage::String
: message to be encodedborder::Int
: width of the white border
styled QR codes
Plot in REPL.
QRCoders.unicodeplot
— Functionunicodeplot(mat::AbstractMatrix{Bool}; border=:none)
Uses UnicodePlots.jl to draw the matrix.
Note: In UnicodePlots.jl, matrix index start from the left-down corner.
unicodeplot(message::AbstractString
; border=:none)
Uses UnicodePlots.jl to draw the QR code of message
.
QRCoders.unicodeplotbychar
— Functionunicodeplotbychar(mat::AbstractMatrix)
Plot of the QR code using Unicode characters.
The value 1(true)
represents a dark space and 0(false)
a white square. It is the same convention as QR code and is the opposite of general image settings.
unicodeplotbychar(message::AbstractString)
Plot of the QR code using Unicode characters.
Encoding modes
There are five several encoding mode currently supported.
QRCoders.Mode
— TypeAbstract type that groups the five supported encoding modes Numeric
, Alphanumeric
, Byte
, Kanji
and UTF8
.
QRCoders.Numeric
— TypeEncoding mode for messages composed of digits only.
QRCoders.Alphanumeric
— TypeEncoding mode for messages composed of digits, characters A
-Z
(capital only) , space and %
*
+
-
.
/
:
$
.
QRCoders.Byte
— TypeEncoding mode for messages composed of one-byte characters(unicode range from 0x00 to 0xff, including ISO-8859-1 and undefined characters)
QRCoders.Kanji
— TypeEncoding mode for messages composed of Shift JIS(Shift Japanese Industrial Standards) characters.
QRCoders.UTF8
— TypeEncoding mode for messages composed of utf-8 characters.
Error Correction
There are four error correction levels you can choose from.
QRCoders.ErrCorrLevel
— TypeAbstract type that groups the four error correction levels Low
, Medium
, Quartile
and High
.
QRCoders.Low
— TypeError correction level that can restore up to 7% of missing codewords.
QRCoders.Medium
— TypeError correction level that can restore up to 15% of missing codewords.
QRCoders.Quartile
— TypeError correction level that can restore up to 25% of missing codewords.
QRCoders.High
— TypeError correction level that can restore up to 30% of missing codewords.
Examples
Create a QR code matrix.
julia> using QRCoders
julia> qrcode("Hello world!")
21×21 BitMatrix:
1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1
1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1
1 0 1 1 1 0 1 0 0 0 1 1 0 0 1 0 1 1 1 0 1
⋮ ⋮ ⋮ ⋮ ⋮
1 0 1 1 1 0 1 0 1 0 0 0 1 0 0 1 0 0 1 0 0
1 0 0 0 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 0 1
1 1 1 1 1 1 1 0 1 0 1 1 0 1 1 1 0 0 1 0 0
Export a QR code image from message.
julia> exportqrcode("Hello world!")
A file will be saved at ./qrcode.png
.
Create a .gif
file from messages.
julia> # QR codes with different masks
julia> using QRCoders: penalty
julia> codes = [QRCode("Hello world!", mask = i) for i in 0:7]
julia> qrcode.(codes) .|> penalty |> print
[425, 485, 342, 318, 495, 562, 368, 415]
julia> exportqrcode(codes, fps=3)