barcode

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package barcode provides one-dimensional and two-dimensional barcode generation using github.com/boombuler/barcode. Supported types include Code128, Code39, Code93, Codabar, EAN-13, EAN-8, UPC-A, 2-of-5, PDF417, DataMatrix, and Aztec Code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aztec

func Aztec(content string, width, height int) (image.Image, error)

Aztec generates an Aztec 2D barcode.

func Codabar

func Codabar(content string, width, height int) (image.Image, error)

Codabar generates a Codabar barcode (digits and -$:/.+ABCD).

func Code39

func Code39(content string, width, height int) (image.Image, error)

Code39 generates a Code39 barcode (uppercase A-Z, 0-9, and - . $ / + % SPACE).

func Code93

func Code93(content string, width, height int) (image.Image, error)

Code93 generates a Code93 barcode (full ASCII via shift characters).

func Code128

func Code128(content string, width, height int) (image.Image, error)

Code128 generates a Code128 barcode (supports full ASCII).

func DataMatrix

func DataMatrix(content string, width, height int) (image.Image, error)

DataMatrix generates a DataMatrix 2D barcode.

func EAN8

func EAN8(content string, width, height int) (image.Image, error)

EAN8 generates an EAN-8 barcode (7 or 8 digits; checksum is auto-calculated if 7 digits are provided).

func EAN13

func EAN13(content string, width, height int) (image.Image, error)

EAN13 generates an EAN-13 barcode (12 or 13 digits; checksum is auto-calculated if 12 digits are provided).

func Generate

func Generate(typ BarcodeType, content string) (image.Image, error)

Generate creates a barcode of the specified type from the given content. The returned image is the raw barcode at 1 module per pixel; use Scale or GenerateScaled for a pixel-sized output. Returns an error for invalid content (e.g. wrong length for EAN).

func GeneratePNG

func GeneratePNG(typ BarcodeType, content string, width, height int) ([]byte, error)

GeneratePNG creates a barcode and encodes it as PNG bytes.

func GenerateScaled

func GenerateScaled(typ BarcodeType, content string, width, height int) (image.Image, error)

GenerateScaled creates a barcode and scales it to the given pixel dimensions. For 1D barcodes, width should be much larger than height.

func PDF417

func PDF417(content string, width, height int) (image.Image, error)

PDF417 generates a PDF417 stacked barcode (high capacity, binary-safe).

func Save

func Save(typ BarcodeType, content, path string, width, height int) error

Save generates a barcode and writes it to a PNG file.

func TwoOfFive

func TwoOfFive(content string, width, height int) (image.Image, error)

TwoOfFive generates an Industrial 2-of-5 barcode (digits only).

func UPC_A

func UPC_A(content string, width, height int) (image.Image, error)

UPC_A generates a UPC-A barcode (11 or 12 digits; checksum is auto-calculated if 11 digits are provided).

Types

type BarcodeType

type BarcodeType string

BarcodeType identifies the barcode symbology.

const (
	TypeCode128    BarcodeType = "code128"
	TypeCode39     BarcodeType = "code39"
	TypeCode93     BarcodeType = "code93"
	TypeCodabar    BarcodeType = "codabar"
	TypeEAN13      BarcodeType = "ean13"
	TypeEAN8       BarcodeType = "ean8"
	TypeUPCA       BarcodeType = "upca"
	TypeTwoOfFive  BarcodeType = "2of5"
	TypePDF417     BarcodeType = "pdf417"
	TypeDataMatrix BarcodeType = "datamatrix"
	TypeAztec      BarcodeType = "aztec"
)

type Metadata

type Metadata struct {
	CodeKind   string // barcode type name (e.g. "Code 128")
	Dimensions byte   // 1 for 1D, 2 for 2D
	Content    string // encoded content
}

Metadata holds information about a generated barcode.

func GetMetadata

func GetMetadata(img image.Image) (*Metadata, error)

GetMetadata extracts metadata from a generated barcode image. Only works on unscaled barcodes (before barcode.Scale is applied).

Jump to

Keyboard shortcuts

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