barcode

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: MIT Imports: 5 Imported by: 0

README

Introduction

This is a package for GO which can be used to create different types of barcodes.

Supported Barcode Types

  • 2 of 5
  • Aztec Code
  • Codabar
  • Code 128
  • Code 39
  • Code 93
  • Datamatrix
  • EAN 13
  • EAN 8
  • PDF 417
  • QR Code

Example

This is a simple example on how to create a QR-Code and write it to a png-file

package main

import (
	"image/png"
	"os"

	"git.bbr-dev.info/brajkovic/barcode"
	"git.bbr-dev.info/brajkovic/barcode/qr"
)

func main() {
	// Create the barcode
	qrCode, _ := qr.Encode("Hello World", qr.M, qr.Auto)

	// Scale the barcode to 200x200 pixels
	qrCode, _ = barcode.Scale(qrCode, 200, 200)

	// create the output file
	file, _ := os.Create("qrcode.png")
	defer file.Close()

	// encode the barcode as png
	png.Encode(file, qrCode)
}

Documentation

See GoDoc

To create a barcode use the Encode function from one of the subpackages.

Documentation

Index

Constants

View Source
const (
	TypeAztec           = "Aztec"
	TypeCodabar         = "Codabar"
	TypeCode128         = "Code 128"
	TypeCode39          = "Code 39"
	TypeCode93          = "Code 93"
	TypeDataMatrix      = "DataMatrix"
	TypeEAN8            = "EAN 8"
	TypeEAN13           = "EAN 13"
	TypePDF             = "PDF417"
	TypeQR              = "QR Code"
	Type2of5            = "2 of 5"
	Type2of5Interleaved = "2 of 5 (interleaved)"
)

Variables

View Source
var ColorScheme16 = ColorScheme{
	Model:      color.Gray16Model,
	Background: color.White,
	Foreground: color.Black,
}

ColorScheme16 represents a color scheme with 16-bit grayscale colors.

View Source
var ColorScheme24 = ColorScheme{
	Model:      color.RGBAModel,
	Background: color.RGBA{255, 255, 255, 255},
	Foreground: color.RGBA{0, 0, 0, 255},
}

ColorScheme24 represents a color scheme with 24-bit RGB colors.

View Source
var ColorScheme32 = ColorScheme{
	Model:      color.RGBAModel,
	Background: color.RGBA{255, 255, 255, 255},
	Foreground: color.RGBA{0, 0, 0, 255},
}

ColorScheme32 represents a color scheme with 32-bit RGBA colors, which is similar to ColorScheme24 but typically includes alpha for transparency.

View Source
var ColorScheme8 = ColorScheme{
	Model:      color.GrayModel,
	Background: color.Gray{Y: 255},
	Foreground: color.Gray{Y: 0},
}

ColorScheme8 represents a color scheme with 8-bit grayscale colors.

Functions

This section is empty.

Types

type Barcode

type Barcode interface {
	image.Image
	// returns some meta information about the barcode
	Metadata() Metadata
	// the data that was encoded in this barcode
	Content() string
}

a rendered and encoded barcode

func Scale

func Scale(bc Barcode, width, height int) (Barcode, error)

Scale returns a resized barcode with the given width and height.

func ScaleWithFill added in v1.0.3

func ScaleWithFill(bc Barcode, width, height int, fill color.Color) (Barcode, error)

Scale returns a resized barcode with the given width, height and fill color.

type BarcodeColor added in v1.0.3

type BarcodeColor interface {
	ColorScheme() ColorScheme
}

type BarcodeIntCS

type BarcodeIntCS interface {
	Barcode
	CheckSum() int
}

Additional interface that some barcodes might implement to provide the value of its checksum.

type ColorScheme added in v1.0.3

type ColorScheme struct {
	Model      color.Model // Color model to be used (e.g., grayscale, RGB, RGBA)
	Background color.Color // Color of the background
	Foreground color.Color // Color of the foreground (e.g., bars in a barcode)
}

ColorScheme defines a structure for color schemes used in barcode rendering. It includes the color model, background color, and foreground color.

type Metadata

type Metadata struct {
	// the name of the barcode kind
	CodeKind string
	// contains 1 for 1D barcodes or 2 for 2D barcodes
	Dimensions byte
}

Contains some meta information about a barcode

Directories

Path Synopsis
Package aztec can create Aztec Code barcodes
Package aztec can create Aztec Code barcodes
Package codabar can create Codabar barcodes
Package codabar can create Codabar barcodes
Package code128 can create Code128 barcodes
Package code128 can create Code128 barcodes
Package code39 can create Code39 barcodes
Package code39 can create Code39 barcodes
Package code93 can create Code93 barcodes
Package code93 can create Code93 barcodes
Package datamatrix can create Datamatrix barcodes
Package datamatrix can create Datamatrix barcodes
Package ean can create EAN 8 and EAN 13 barcodes.
Package ean can create EAN 8 and EAN 13 barcodes.
Package pdf417 can create PDF-417 barcodes
Package pdf417 can create PDF-417 barcodes
Package qr can be used to create QR barcodes.
Package qr can be used to create QR barcodes.
Package twooffive can create interleaved and standard "2 of 5" barcodes.
Package twooffive can create interleaved and standard "2 of 5" barcodes.
Package utils contain some utilities which are needed to create barcodes
Package utils contain some utilities which are needed to create barcodes

Jump to

Keyboard shortcuts

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