View Source QRCode.QR (QRCode v3.1.0)
QR code data structure
Summary
Types
@type groups() :: {[[], ...], [[]]}
@type level() :: :low | :medium | :quartile | :high
@type mask_num() :: 0..7
@type mode() :: :numeric | :alphanumeric | :byte | :kanji | :eci
@type version() :: 1..40
Functions
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, 0, 1, 1, 1, 0, 1],
[1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0],
[0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1],
[1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1],
[0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0],
[1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0],
[1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0],
[1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
[1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 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, you have to render it first and then save it:
iex> qr = QRCode.QR.create("Hello World", :high)
iex> qr |> QRCode.render() |> QRCode.save("hello.svg")
{:ok, "hello.svg"}
The svg file will be saved into your project directory.
The same as create/2
, but raises a QRCode.Error
exception if it fails.