View Source Qrusty (qrusty v0.1.2)

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)

svg

SVG

> {:ok, %Qrusty.QR{encoded_data: svg}} = Qrusty.qr("https://elixir-lang.org/", :svg, size: 200)

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>
FormatSample
SVG svg
PNG png
JPG jpg
PNG64 sample
JPG64--

Link to this section Summary

Link to this section Types

@type data() :: String.t()
@type format() :: :svg | :png | :jpg | :jpeg | :png64 | :jpg64 | :jpeg64
@type opts() :: [size: integer(), height: integer(), width: integer()] | []

Link to this section Functions

Link to this function

qr(data, format, opts \\ [])

View Source
@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/", size: 100);
{:ok, %QR{}}

iex>  Qrusty.qr("https://elixir-lang.org/", width: 100, height: 100);
{:ok, %QR{}}