Qrusty

QR Code generator that leverages precompiled Rust.

The "precompiled" implies that using this library does not require installing Rust.

Installation

QRusty at the moment is NOT on Hex.

The package can be installed by adding qrusty to your list of dependencies in mix.exs:

def deps do
[
{:qrusty, github: "nbw/qrusty"}
]
end

Usage

The following QR formats are supported:

SVG

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

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, width: 200, height: 200)
File.write("./assets/qr.jpg", binary)

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--

Benchmarks

Benchmarks have been included to compare Qrusty (Rust based) to EQRCode (Elixir based), as it's the defacto Elixir QR Code library.

Note: since the execution time of generating a single QR code is so fast, benchmarking was not very accurate. To compensate, the benchmarks measure the execution time for generating 100 QR codes.

Usage

Run the following:

mix run benchmarks/png.exs
mix run benchmarks/svg.exs
...

Summary

The full results are here.

Qrusty vs EQRCode (x times faster)

100x100200x200500x500
PNG27.43x18.86x7.21x
SVG42.83x44.02x43.87x
JPG---

Trends: QRusty executes faster than QRCode, but the gains decrease with larger image sizes.

Development

You will need the following installed:

Compiling QRusty

mix compile.local

Contributions

Contributions are welcome.

Rust Contribution Rules

Basically, the end user is an Elixir developer, so keep as much code as possible in Elixir for readability. Leverage Rust only for its performance benefits/access to system level libraries, etc. 🙏

Thanks

Copyright and License

This library is released under the MIT License. See the LICENSE.md file.