/qr-code-svg

Library for generating QR code to SVG format. DEPRECATED!

Primary LanguageElixirOtherNOASSERTION

This library is DEPRECATED! Please use our new library QRCode.

QrCodeSvg

This library generates QR code to SVG format. It is based on Sunboshan's library and another inspiration came from beautiful Pete Corey's article.

Installation

If available in Hex, the package can be installed by adding qr_code_svg to your list of dependencies in mix.exs:

def deps do
  [
    # {:qr_code_svg, "~> 1.2.1"} # This does not work because sunboshan/qrcode is not at hex.pm
    {:qr_code_svg, git: "https://github.com/ondrej-tucek/qr-code-svg", tag: "v1.2.1"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/qr_code_svg.

Usage

Using this library is simple, just call function:

QrCodeSvg.generate("Put your string here...", "qr_code.svg")

Of course, there are a couple settings for creating svg:

Setting Type Default value Description
scale integer 10 scale for svg QR code
background_color [ string \ {r, g, b} ] "#ffffff" background color of svg
qrcode_color [ string \ {r, g, b} ] "#000000" color of QR code

For example, if you want to change color of QR code, it's enough to write

QrCodeSvg.generate(
    "Put your string here...",
    "qr_code.svg",
    %SvgSettings{qrcode_color: {17, 170, 136}}
  )

Notes:

  • QRCode.Matrix can contain a couple of nil elements for some input string. I don't know if this behaviour is correct or not. The questions were placed to author of qrcode library and in elixirforum. For now, the 'nil' values are not considered in svg. It means the 'nil's will display as squares of white color. And it seems that everything works fine. ☺️
  • svg file is created in root directory
  • thanks to scale in %SvgSettings{} we can change a size of generated svg
  • byte_size of QR encoding string is bounded above by 154
  • ECC Level of QR is only L, see Sunboshan's library
  • mogrify utility was used for convert svg examples to png files in this a way:
import Mogrify

"qr_code.svg"
  |> Mogrify.open()
  |> format("png")
  |> save(path: "qr_code.png")

License

MIT