QRCode - a library for generating QR code

Hi folks!

We’ve just finished (me and @smita) our new QRCode library for Elixir. Now you can generate QR code whenever you’ll want… :tada:

Basic usage looks like:

iex> qr = QRCode.create("Hello World")
iex> qr |> Result.and_then(&QRCode.Svg.save_as(&1,"/path/to/hello.svg"))
{:ok, "/path/to/hello.svg"}

If you want to change, for example, ecc level and the color of QR code you can write

iex> settings = %QRCode.SvgSettings{qrcode_color: {17, 170, 136}}
iex> qr = QRCode.create("quiz_string", :high)
iex> qr |> Result.and_then(&QRCode.Svg.save_as(&1, "/path/to/quiz.svg", settings))
{:ok, "/path/to/quiz.svg"}


Let’s try to decode the QR code above by your QR reader. You can find the result below…


  • this library was developed only for Byte mode
  • as side project was developed MatrixReloaded library for manipulating with matrices and vectors

Comments, what improve, what make better,… are welcome.

Happy QR coding.

quiz_string =

Find what you love and let it kill you.
Charles Bukowski


QRCode v3.0.0 is out!

See news below:


  • The main usage is now simplified:

    # QRCode.create() has default :low error correction and :byte mode
    |> QRCode.create() 
    |> QRCode.render() 
    |> QRCode.save("/tmp/qr_code.svg")

    Instead of QRCode.save(), you can use a function QRCode.to_base64() to encode QR to base 64.

  • In SVG settings was changed the option :format with type :none or :indent on :structure with :minify (default value) or :readable for more clearer using. The variable :structure now reflects the structure of svg file. The final svg can be minified using by :minify or :readable and thus little bit larger.


  • Alphanumeric mode, thank for mpichette contribution.

    # QRCode.render() has default :svg and SvgSettings
    |> QRCode.create(:low, :alphanumeric) 
    |> QRCode.render() 
    |> QRCode.save("/tmp/qr_code.svg")
  • Embedded image to svg. Support embedded image are only type: jpeg, jpg, png, or svg.

    # image = {".../path/to/name.type", size}, where size must be positive integer and means how embedded image will be large in the final svg file
    iex> alias QRCode.Render.SvgSettings
    iex> image = {"/docs/elixir.svg", 100}
    iex> qr_color = {17, 170, 136}
    iex> svg_settings = %SvgSettings{qrcode_color: qr_color, image: image, structure: :readable}
      background_color: "#ffffff",
      background_opacity: nil,
      image: {"/docs/elixir.svg", 100},
      qrcode_color: {17, 170, 136},
      scale: 10,
      structure: :readable
    iex> "your_string"
          |> QRCode.create()
          |> QRCode.render(:svg, svg_settings)
          |> QRCode.save("/tmp/qr-with-image.svg")
      {:ok, "/tmp/qr-with-image.svg"}


  • Png render. You can save the QR to png file.

    # You can use PngSettings similar as above in QRCode.render(:svg) 
    |> QRCode.render(:png) 
    |> QRCode.save("/tmp/qr_code.png")

More information and examples will find on hex.pm or check the Github library.