QRCode v2.0.1 QRCode.Svg View Source

SVG structure and helper functions.

Link to this section Summary

Functions

Saves QR code to svg file. This function returns Result, it means either tuple of {:ok, "path/to/file.svg"} or {:error, reason}.

Link to this section Types

Link to this type

t() View Source
t() :: %QRCode.Svg{
  body: String.t(),
  height: ExMaybe.t(integer()),
  rank_matrix: ExMaybe.t(pos_integer()),
  width: ExMaybe.t(integer()),
  xlink: String.t(),
  xmlns: String.t()
}

Link to this section Functions

Link to this function

save_as(qr, svg_name, settings \\ %SvgSettings{}) View Source
save_as(QRCode.QR.t(), Path.t(), QRCode.SvgSettings.t()) ::
  Result.t(String.t() | File.posix() | :badarg | :terminated, Path.t())

Saves QR code to svg file. This function returns Result, it means either tuple of {:ok, "path/to/file.svg"} or {:error, reason}.

Also there are a few settings for svg:

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

By this option, you can set the background of QR code, QR code colors or size QR code. Let's see an example below:

iex> settings = %QRCode.SvgSettings{qrcode_color: {17, 170, 136}}
iex> qr = QRCode.QR.create("your_string")
iex> qr |> Result.and_then(&QRCode.Svg.save_as(&1,"/tmp/your_name.svg", settings))
{:ok, "/tmp/your_name.svg"}

The svg file will be saved into your tmp directory.

QR code color