qrkit/render/png
Pure Gleam PNG renderer for qrkit QR codes.
Types
Rendering options for to_bit_array_with.
Mirrors the shape of qrkit/render/svg’s SvgOptions. The
colour fields accept CSS-style hex strings (#rgb, #rrggbb, or
#rrggbbaa); unparseable values fall back to the default colour
rather than rejecting the call, so callers can keep the surface
non-fallible.
pub opaque type PngOptions
Values
pub fn default_options() -> PngOptions
Default PNG rendering options: 8×8 px modules, 4-module quiet
zone, black on white, background on. Mirrors
qrkit/render/svg’s defaults.
pub fn to_bit_array(
qr: qrkit.QrCode,
scale scale: Int,
margin margin: Int,
) -> BitArray
Render a QR code as PNG bytes.
scale values less than 1 are normalised to 1, and negative margin
values are normalised to 0. Thin wrapper around
to_bit_array_with using the default
black-on-white palette.
pub fn to_bit_array_with(
qr: qrkit.QrCode,
options: PngOptions,
) -> BitArray
Render a QR code as PNG bytes using the options builder.
Equivalent to to_bit_array when called with
default_options overridden only by
with_module_size and
with_margin; the colour and background knobs
add the surface not previously reachable through the positional
entry point.
pub fn with_background(
options: PngOptions,
draw: Bool,
) -> PngOptions
Toggle whether the light/background pixels are drawn opaquely.
When False, the light palette entry is marked transparent via a
tRNS chunk so the QR code can be composited over an existing
background.
pub fn with_dark_color(
options: PngOptions,
css_color: String,
) -> PngOptions
Set the dark module colour. Accepts #rgb, #rrggbb, or
#rrggbbaa — same syntax as the SVG renderer. Unparseable
strings keep the previous value rather than failing the call.
pub fn with_light_color(
options: PngOptions,
css_color: String,
) -> PngOptions
Set the light / background colour. Accepts the same hex syntax as
with_dark_color.
pub fn with_margin(
options: PngOptions,
modules: Int,
) -> PngOptions
Set the quiet-zone margin in modules.
Negative values are normalised to 0.
pub fn with_module_size(
options: PngOptions,
px: Int,
) -> PngOptions
Set the PNG module size in pixels.
Values less than 1 are normalised to 1 to keep the rendered output usable.