/qrcoder

A Rust NIF for creating SVG QR codes

Primary LanguageElixirMIT LicenseMIT

QRCoder

Build Status

An Elixir Rust NIF to create SVG QR codes. It's a wrapper around qrcode-rust.

Installation

You can find QRCoder in Hex.pm and you can add it to your project dependencies:

# mix.exs
def deps do
  [
    {:qr_coder, "~> 0.1.0"}
  ]
end

Usage

You can then call the function:

{:ok, svg} = QRCoder.generate_svg("Elixir is awesome")

This will return a tuple where svg is black & white svg binary:

alt text

You can change the dark color by providing a valid HEX color:

{:ok, svg} = QRCoder.generate_svg("Elixir is awesome", "#21ABA5")

alt text

You can then save it:

{:ok, svg} = QRCoder.generate_svg("Elixir is awesome")
File.write("/your/path/qrcode.svg", svg)

Or just return the binary:

# inside a Phoenix controller
{:ok, svg} = QRCoder.generate_svg("Elixir is awesome")

conn
|> put_resp_header("content-type", "image/svg+xml")
|> put_resp_header("cache-control", "private")
|> send_resp(200, svg)