View Source Qrusty (qrusty v0.1.6)
Documentation for Qrusty
QR Code generator that leverages precompiled Rust.
The "precompiled" implies that using this library does not require installing Rust.
usage
Usage
The following QR formats are supported:
- SVG (
:svg
) - PNG (
:png
) - JPG (
:jpg
) - base64 PNG (
:png64
) - base64 JPG (
:jpg64
)
options
Options
- width: width in pixels (default: 200)
- height: height in pixels (default: 200)
- size: shorthand for width and height (default: 200)
- ec: error correction level
:l
,:m
,:q
,:h
(default: :m)
svg
SVG
> {:ok, %Qrusty.QR{encoded_data: svg}} = Qrusty.qr("https://elixir-lang.org/", :svg, size: 200, ec: :h)
File.write("./assets/qr.svg", svg)
png-jpg
PNG/JPG
> {:ok, %Qrusty.QR{encoded_data: binary}} = Qrusty.qr("https://elixir-lang.org/", :png, width: 200, height: 200)
File.write("./assets/qr.png", binary)
> {:ok, %Qrusty.QR{encoded_data: binary}} = Qrusty.qr("https://elixir-lang.org/", :jpg, size: 200)
File.write("./assets/qr.jpg", binary)
base64-png-jpg
Base64 PNG/JPG
# :png64 or :jpg64
> {:ok, %Qrusty.QR{encoded_data: binary_64}} = Qrusty.qr("https://elixir-lang.org/", :png64, width: 200, height: 200)
# Heex Template (for example)
<a href={"data:image/png;base64, " <> binary_64} download="qr.png">
<img src={"data:image/png;base64, "<> binary_64}></img>
</a>
Format | Sample |
---|---|
SVG | |
PNG | ![]() |
JPG | ![]() |
PNG64 | sample |
JPG64 | -- |
Error correction:
L | M | Q | H |
---|---|---|---|
![]() | ![]() | ![]() | ![]() |
Link to this section Summary
Link to this section Types
@type data() :: String.t()
@type error_correction() :: :l | :m | :q | :h
@type format() :: :svg | :png | :jpg | :jpeg | :png64 | :jpg64 | :jpeg64
@type opts() :: [size: integer(), height: integer(), width: integer(), ec: error_correction()] | []
Link to this section Functions
Generate a QR code.
example
Example
iex> Qrusty.qr!("https://elixir-lang.org/", :svg, size: 100);
"..."
Raises `Qrusty.Error` if the input is invalid
@spec qr(data(), format(), opts()) :: {:ok, %Qrusty.QR{ data: term(), encoded_data: term(), format: term(), height: term(), width: term() }} | {:error, any()}
Generate a QR code.
example
Example
iex> Qrusty.qr("https://elixir-lang.org/", :svg, size: 100);
{:ok, %QR{}}
iex> Qrusty.qr("https://elixir-lang.org/", :png, width: 100, height: 100);
{:ok, %QR{}}