View Source QRNBU.Renderer.Logo (NBU payment QR v0.3.3)
Logo embedding functionality for SVG QR codes.
This module handles embedding logos (UAH sign by default, or custom logos) into the center of SVG QR codes. The logo is precisely aligned to QR code module boundaries for clean visual integration.
Logo Options
true- Use the default UAH currency sign logo (with white circle background)false- No logo (plain QR code)"/path/to/logo.svg"- Custom SVG logo from file path (no background){:svg, "<svg>...</svg>"}- Inline SVG string (no background)
Grid-Aligned Positioning
The logo is snapped to QR module grid boundaries:
- Logo size is rounded to an odd number of modules for perfect centering
- Position coordinates are integers aligned to module edges
- Occupies approximately 25% of the QR code (within H-level error correction tolerance)
Example: For a 69x69 module QR code, logo covers 17x17 modules centered at position (26, 26).
Summary
Types
Functions
@spec default_logo_path() :: String.t()
Returns the path to the default UAH logo.
@spec embed(String.t(), logo_option(), number()) :: {:ok, String.t()} | {:error, String.t()}
Embeds a logo into an SVG QR code string.
The logo is precisely aligned to QR module grid boundaries for clean integration.
Parameters
svg_string- The SVG QR code stringlogo_option- Logo specification (see module docs)width- The QR code width (used for reference, positioning uses viewBox)
Returns
{:ok, svg_with_logo}- SVG string with embedded logo{:error, reason}- Error message
Examples
iex> {:ok, svg} = QRNBU.Renderer.to_svg("test", logo: false)
iex> {:ok, svg_with_logo} = QRNBU.Renderer.Logo.embed(svg, true, 300)
iex> String.contains?(svg_with_logo, "uah-logo")
true