QRCode v2.0.1 QRCode.QR View Source
QR code data structure
Link to this section Summary
Link to this section Types
Link to this type
groups()
View Source
groups()
View Source
groups() :: {[[], ...], [[]]}
groups() :: {[[], ...], [[]]}
Link to this type
level()
View Source
level()
View Source
level() :: :low | :medium | :quartile | :high
level() :: :low | :medium | :quartile | :high
Link to this type
mask_num()
View Source
mask_num()
View Source
mask_num() :: 0..7
mask_num() :: 0..7
Link to this type
mode()
View Source
mode()
View Source
mode() :: :numeric | :alphanumeric | :byte | :kanji | :eci
mode() :: :numeric | :alphanumeric | :byte | :kanji | :eci
Link to this type
version()
View Source
version()
View Source
version() :: 1..40
version() :: 1..40
Link to this section Functions
Link to this function
create(orig, level \\ :low) View Source
Creates QR code. You can change the error correction level according to your needs.
There are four level of error correction: :low | :medium | :quartile | :high
where :low
is default value.
This function returns Result,
it means either tuple of {:ok, QR.t()}
or {:error, "msg"}
.
Example:
iex> QRCode.QR.create("Hello World")
{:ok,
%QRCode.QR{
ecc: %QRCode.ErrorCorrection{
blocks_in_group1: 1,
blocks_in_group2: 0,
codewords: {[[139, 194, 132, 243, 72, 115, 10]], []},
codewords_per_block_in_group1: 19,
codewords_per_block_in_group2: 0,
ec_codewrods_per_block: 7,
groups: {[
[64, 180, 134, 86, 198, 198, 242, 5, 118, 247, 38, 198, 64, 236, 17,
236, 17, 236, 17]
], []}
},
ecc_level: :low,
encoded: <<64, 180, 134, 86, 198, 198, 242, 5, 118, 247, 38, 198, 64, 236,
17, 236, 17, 236, 17>>,
mask_num: 0,
matrix: [
[1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1],
[1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 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0, 1, 0, 0, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1]
],
message: <<64, 180, 134, 86, 198, 198, 242, 5, 118, 247, 38, 198, 64, 236,
17, 236, 17, 236, 17, 139, 194, 132, 243, 72, 115, 10>>,
mode: :byte,
orig: "Hello World",
version: 1
}}
For saving QR code to svg file, use QRCode.Svg.save_as/3
function:
iex> qr = QRCode.QR.create("Hello World", :high)
iex> qr |> Result.and_then(&QRCode.Svg.save_as(&1,"hello.svg"))
{:ok, "hello.svg"}
The svg file will be saved into your project directory.
Link to this function
create!(text, level \\ :low) View Source
The same as create/2
, but raises a QRCode.Error
exception if it fails.
Link to this macro
level(lvl) View Source (macro)
Link to this macro
masking(m) View Source (macro)
Link to this macro