Documentation
¶
Overview ¶
Package render produces 1-bit-friendly grayscale image.Image values suitable for the printer.PrintImage path. Every renderer takes a target width in pixels and returns an image whose width matches.
Index ¶
- Variables
- func DecodeImage(r io.Reader) (image.Image, error)
- func Dither(src image.Image) image.Image
- func Dragon(iter, targetWidth int) image.Image
- func Face(family string, size float64) font.Face
- func FamilyNames() string
- func FitWidth(src image.Image, targetW int) image.Image
- func FontSampler(sample string, width int) (image.Image, error)
- func Gosper(order, targetWidth int) image.Image
- func Gradient(width, h int) image.Image
- func Hilbert(order, targetWidth int) image.Image
- func LoadImage(path string) (image.Image, error)
- func MonoText(s string, width int, ptSize float64) (image.Image, error)
- func PDF417(data string, width, errLevel int) (image.Image, error)
- func QR(data string, width int) (image.Image, error)
- func Rotate(src image.Image, deg int) image.Image
- func Rotate90(src image.Image) image.Image
- func Rotate180(src image.Image) image.Image
- func Rotate270(src image.Image) image.Image
- func Rule(width, h int) image.Image
- func RuleAutomaton(rule byte, width, rows int) image.Image
- func SetDefaultFamily(name string) error
- func SetMonospaceFamily(name string) error
- func Solid(width, h int) image.Image
- func Sparkline(values []float64, w, h int) image.Image
- func Text(s string, width int, ptSize float64) (image.Image, error)
- func TextWithFace(s string, width int, face font.Face) (image.Image, error)
- func Uniform(width, h int, level uint8) image.Image
- func VStack(gap int, parts ...image.Image) image.Image
- type Family
Constants ¶
This section is empty.
Variables ¶
var AllFonts = []struct { Name string Face font.Face }{ {"Spleen 8", fonts.MiscSpleenMedium8}, {"Spleen 12", fonts.MiscSpleenMedium12}, {"Spleen 16", fonts.MiscSpleenMedium16}, {"Spleen 24", fonts.MiscSpleenMedium24}, {"Apple Helvetica 9", fonts.AppleHelveticaMedium9}, {"Apple Helvetica 10", fonts.AppleHelveticaMedium10}, {"Apple Helvetica 12", fonts.AppleHelveticaMedium12}, {"Apple Helvetica 14", fonts.AppleHelveticaMedium14}, {"Apple Helvetica 18", fonts.AppleHelveticaMedium18}, {"Apple Helvetica 24", fonts.AppleHelveticaMedium24}, {"Apple Times 9", fonts.AppleTimesMedium9}, {"Apple Times 10", fonts.AppleTimesMedium10}, {"Apple Times 12", fonts.AppleTimesMedium12}, {"Apple Times 14", fonts.AppleTimesMedium14}, {"Apple Times 18", fonts.AppleTimesMedium18}, {"Apple Times 24", fonts.AppleTimesMedium24}, {"Apple Geneva 9", fonts.AppleGenevaMedium9}, {"Apple Geneva 10", fonts.AppleGenevaMedium10}, {"Apple Geneva 12", fonts.AppleGenevaMedium12}, {"Apple Geneva 14", fonts.AppleGenevaMedium14}, {"Apple Geneva 18", fonts.AppleGenevaMedium18}, {"Apple Geneva 20", fonts.AppleGenevaMedium20}, {"Apple Geneva 24", fonts.AppleGenevaMedium24}, {"Apple Monaco 9", fonts.AppleMonacoMedium9}, {"Apple Monaco 12", fonts.AppleMonacoMedium12}, {"Apple Chicago 12", fonts.AppleChicagoMedium12}, {"Apple Courier 9", fonts.AppleCourierMedium9}, {"Apple Courier 10", fonts.AppleCourierMedium10}, {"Apple Courier 12", fonts.AppleCourierMedium12}, {"Apple Courier 14", fonts.AppleCourierMedium14}, {"Apple Courier 18", fonts.AppleCourierMedium18}, {"Apple Courier 24", fonts.AppleCourierMedium24}, {"Sun Gallant 19", fonts.SunGallantDemi19}, }
AllFonts is the catalog of vendored bitmap fonts. Order = display order in the font sampler.
var DefaultFamily = "helvetica"
DefaultFamily is consulted by pickFace for non-monospace text. Set via SetDefaultFamily.
var MonospaceFamily = "monaco"
MonospaceFamily is the fixed-width family used by callers that want code-style text (markdown code blocks). Set via SetMonospaceFamily.
Functions ¶
func DecodeImage ¶
DecodeImage decodes from any registered format.
func Dither ¶
Dither converts a grayscale-ish image to 1-bit using Floyd–Steinberg error diffusion. Returned image is "1 = black" for direct packing.
Operates on a fresh grayscale buffer so the caller's image isn't mutated. Transparent source pixels become white, not black — many PNG sources (e.g. clip art) use a transparent background.
func Dragon ¶
Dragon returns a Heighway dragon curve at iter folding iterations, scaled to fit targetWidth. iter=12 gives 4096 segments in a ~64x32 bounding grid — the densest stage where folds are still legible.
func Face ¶
Face returns the bitmap face nearest the requested size in the named family, rounding up. Unknown families fall back to helvetica.
func FamilyNames ¶
func FamilyNames() string
FamilyNames returns the comma-separated list of known family names, useful for error messages.
func FitWidth ¶
FitWidth resizes src to exactly targetW pixels wide, preserving aspect ratio. Catmull-Rom — good for both photos and clean diagrams.
func FontSampler ¶
FontSampler renders one labeled line per vendored font with the given sample text.
func Gosper ¶
Gosper returns the order-N flowsnake (Gosper) curve scaled to fit targetWidth. Order 4 = 2401 segments; the curve fills a hexagonal region with a self-similar boundary.
func Hilbert ¶
Hilbert returns an order-N Hilbert space-filling curve drawn at the largest integer pixels-per-cell that fits within targetWidth. The canvas is square. Order 7 is the visually densest that still resolves individual line segments at 384 px wide.
func MonoText ¶
MonoText renders with the active MonospaceFamily — used for code blocks and anything else that wants column-aligned text.
func PDF417 ¶
PDF417 builds a PDF417 barcode that fills `width` pixels and auto-sizes height based on payload length. iPhone Camera reads it.
errLevel: 0..8 per ISO/IEC 15438 §5.5 — higher = more redundant. Default 2 is plenty for clean thermal prints.
func QR ¶
QR builds a QR-code bitmap that fills `width` pixels at a pixel-perfect scale (no resampling). High error correction so the code survives a thumbprint or fading thermal paper.
func Rotate ¶
Rotate rotates by a multiple of 90 degrees (0, 90, 180, 270). Anything else returns src unchanged.
func Rotate90 ¶
Rotate90 rotates the source image 90° counter-clockwise. Useful for printing landscape photos on a portrait-format thermal head.
func RuleAutomaton ¶
RuleAutomaton renders Wolfram's elementary 1-D cellular automaton for the given rule (0..255) as a width-by-rows strip, starting from a single black cell in the center of the top row.
func SetDefaultFamily ¶
SetDefaultFamily switches the family used by Text(). Returns an error if the name isn't known.
func SetMonospaceFamily ¶
SetMonospaceFamily switches the monospace family. Returns an error if the name isn't known.
func Sparkline ¶
Sparkline draws a tiny line chart of values into a w×h grayscale image. Black on white. Each adjacent pair of values is connected by a 1-pixel straight line; values are normalized to fit between rows 1 and h-2 with a 1-pixel margin top and bottom.
If fewer than 2 values, returns a blank image. If all values are equal the line draws across the vertical center.
func Text ¶
Text renders s into a bitmap of the given width with word wrapping at the actual face's advance widths. Output is pure 1-bit grayscale so it passes through Dither unchanged. Uses DefaultFamily.
func TextWithFace ¶
TextWithFace is Text with an explicit font.Face — useful when you want a specific bitmap (e.g. Apple Chicago for a system-7 vibe).