render

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package render provides image rendering capabilities for ZPL labels. It converts ZPL Label objects to bitmap images that approximate what a Zebra printer would produce.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Renderer

type Renderer struct {
	// DPI is the printer resolution (203, 300, or 600 dots per inch).
	DPI zpl.DPI

	// Width is the label width in dots. If zero, uses the label's configured width.
	Width int

	// Height is the label height in dots. If zero, uses the label's configured height.
	Height int

	// IgnoreLabelHome controls whether ^LH (label home) offsets are applied.
	// When false (default), offsets are applied exactly as a printer would.
	// When true, offsets are ignored for cleaner previews.
	IgnoreLabelHome bool
}

Renderer holds configuration for rendering ZPL labels to images.

func New

func New(dpi zpl.DPI) *Renderer

New creates a new Renderer with the given DPI. Width and height will be taken from the label if not set.

func (*Renderer) Render

func (r *Renderer) Render(label *zpl.Label) (image.Image, error)

Render converts a Label to an image. The returned image uses white background with black elements, matching thermal label printer output.

func (*Renderer) RenderAll

func (r *Renderer) RenderAll(labels []*zpl.Label) ([]image.Image, error)

RenderAll renders multiple labels and returns an image for each.

func (*Renderer) RenderJPEG

func (r *Renderer) RenderJPEG(label *zpl.Label, w io.Writer, quality int) error

RenderJPEG renders the label and writes it as a JPEG image to the writer. Quality should be between 1 and 100, where 100 is best quality.

func (*Renderer) RenderPNG

func (r *Renderer) RenderPNG(label *zpl.Label, w io.Writer) error

RenderPNG renders the label and writes it as a PNG image to the writer.

func (*Renderer) WithIgnoreLabelHome

func (r *Renderer) WithIgnoreLabelHome(ignore bool) *Renderer

WithIgnoreLabelHome sets whether to ignore ^LH label home offsets. When false (default), offsets are applied exactly as a printer would. When true, offsets are ignored for cleaner previews.

func (*Renderer) WithSize

func (r *Renderer) WithSize(width, height int) *Renderer

WithSize sets the label dimensions in dots.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL