QQR.SVG (QQR v0.2.0)

Copy Markdown View Source

SVG renderer for QR code matrices.

Dot shapes

:square            (default)
:rounded           rounded corners (25% radius)
:dots              circles
:diamond           diamond / rotated square

Finder pattern shapes

Finder patterns (the three big squares in corners) can be styled independently with :finder_shape:

:square          default
:rounded         rounded outer ring + rounded inner
:dots            circular outer ring + circular inner

Logo embedding

Pass a :logo option to embed an image or SVG in the center. Modules behind the logo are automatically cleared.

QQR.SVG.render(matrix,
  logo: %{svg: ~s(<circle r="0.4" cx="0.5" cy="0.5" fill="red"/>), size: 0.25}
)

Summary

Types

dot_shape()

@type dot_shape() :: :square | :rounded | :dots | :diamond

finder_shape()

@type finder_shape() :: :square | :rounded | :dots

logo_opts()

@type logo_opts() :: %{
  optional(:svg) => String.t(),
  optional(:image_url) => String.t(),
  optional(:size) => float(),
  optional(:margin) => number(),
  optional(:background) => String.t()
}

option()

@type option() ::
  {:module_size, number()}
  | {:quiet_zone, non_neg_integer()}
  | {:color, String.t()}
  | {:background, String.t()}
  | {:dot_shape, dot_shape()}
  | {:dot_size, float()}
  | {:finder_shape, finder_shape()}
  | {:logo, logo_opts()}

Functions

render(matrix, opts \\ [])

@spec render(QQR.BitMatrix.t(), [option()]) :: String.t()

Render a QQR.BitMatrix as an SVG string.

See to_iodata/2 for options.

to_iodata(matrix, opts \\ [])

@spec to_iodata(QQR.BitMatrix.t(), [option()]) :: iodata()

Render a QQR.BitMatrix as SVG iodata.

Returns iodata (nested list of strings) — avoids an extra binary copy. Pass to IO.iodata_to_binary/1 when you need a string, or use directly in Phoenix templates with raw/1.

Options

  • :module_size — pixel size per module (default: 10)
  • :quiet_zone — quiet zone in modules (default: 4)
  • :color — dark module color (default: "#000")
  • :background — background color (default: "#fff")
  • :dot_shape:square, :rounded, :dots, or :diamond (default: :square)
  • :dot_size — module size multiplier, 0.1–1.0 (default: 1.0)
  • :finder_shape:square, :rounded, or :dots (default: matches :dot_shape or :square)
  • :logo — logo options map (see module doc)