zxing

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

README

zxing-cpp

Go wrapper for zxing-cpp version 2.3.0

Prerequisites

This package requires the ZXing C++ library to be installed with pkg-config support. It depends on the C-API of zxing-cpp.

Installation

Ubuntu/Debian:

# at build time:
sudo apt install libzxing-dev
# at run time libzxing3 is enough
sudo apt install libzxing3

From source:

git clone https://github.com/zxing-cpp/zxing-cpp.git --recursive --single-branch --depth 1 --branch v2.3.0
cd zxing-cpp
cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DZXING_C_API=ON
cmake --build build
sudo cmake --install build
sudo ldconfig

# Create pkg-config file
sudo tee /usr/local/lib/pkgconfig/zxing.pc > /dev/null <<EOF
prefix=/usr/local
exec_prefix=\${prefix}
libdir=\${exec_prefix}/lib
includedir=\${prefix}/include

Name: ZXing
Description: ZXing-C++ library
Version: 2.3.0
Libs: -L\${libdir} -lZXing
Cflags: -I\${includedir} -I\${includedir}/ZXing
EOF

# Update pkg-config path (add to ~/.bashrc for persistence)
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

Verify installation:

pkg-config --cflags --libs zxing

Installation

go get github.com/Mittelstand-ai-GmbH-Co-KG/zxing-cpp

Usage

package main

import (
    "fmt"
    "image/png"
    "os"
    
    "github.com/Mittelstand-ai-GmbH-Co-KG/zxing-cpp"
)

func main() {
    // Open image file
    file, err := os.Open("barcode.png")
    if err != nil {
        panic(err)
    }
    defer file.Close()
    
    // Decode image
    img, err := png.Decode(file)
    if err != nil {
        panic(err)
    }
    
    // Create config and scan
    config := zxing.NewConfig()
    if err != nil {
		panic(err)
	}
	defer config.Close()

    symbols, err := config.Scan(img)
    if err != nil {
        panic(err)
    }
    
    // Print results
    for _, symbol := range symbols {
        fmt.Printf("Type: %s\nData: %s\n", symbol.BcType, symbol.Data)
    }
}

Build with CGO_ENABLED. For example

CGO_ENABLED=1 go build -installsuffix 'static' -o /app .

Supported image types

Supported image types are

image.Gray, image.RGBA, image.NRGBA and image.YCbCr.

Documentation

Index

Constants

View Source
const (
	ORIENTATION_UNSPECIFIED = "ORIENTATION_UNSPECIFIED"
	ORIENTATION_UP          = "UP"
	ORIENTATION_DOWN        = "DOWN"
	ORIENTATION_LEFT        = "LEFT"
	ORIENTATION_RIGHT       = "RIGHT"
)

Orientation string constants for detected barcodes.

View Source
const (
	TYPE_NONE            = "NONE"
	TYPE_AZTEC           = "AZTEC"
	TYPE_CODABAR         = "CODABAR"
	TYPE_CODE39          = "CODE39"
	TYPE_CODE93          = "CODE93"
	TYPE_CODE128         = "CODE128"
	TYPE_DATABAR         = "DATABAR"
	TYPE_DATABAREXPANDED = "DATABAREXPANDED"
	TYPE_DATAMATRIX      = "DATAMATRIX"
	TYPE_EAN8            = "EAN8"
	TYPE_EAN13           = "EAN13"
	TYPE_I25             = "I25"
	TYPE_MAXICODE        = "MAXICODE"
	TYPE_PDF417          = "PDF417"
	TYPE_QRCODE          = "QRCODE"
	TYPE_UPCA            = "UPCA"
	TYPE_UPCE            = "UPCE"
	TYPE_MICROQRCODE     = "MICROQRCODE"
	TYPE_RMQRCODE        = "RMQRCODE"
	TYPE_DXFILMEDGE      = "DXFILMEDGE"
	TYPE_DATABARLIMITED  = "DATABARLIMITED"
	TYPE_UNKNOWN         = "UNKNOWN"
)

Barcode type string constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config wraps internal.Config and specifies barcode detection configuration.

func NewConfig

func NewConfig(formats ...string) (Config, error)

NewConfig creates a new Config for barcode detection, defaulting to all formats.

func (Config) Close

func (c Config) Close()

Close frees resources of the underlying library and should be called

func (Config) Scan

func (c Config) Scan(img image.Image) ([]Symbol, error)

Scan detects barcodes in the provided image and returns a slice of Symbols. Supported image types: image.Gray, image.RGBA, image.NRGBA.

type Point

type Point = internal.Point

Point represents a coordinate in the bounding box of a detected barcode.

type Symbol

type Symbol struct {
	Data        string  // Decoded data from the barcode
	BcType      string  // Barcode type (e.g., TYPE_I25)
	Polygon     []Point // Bounding polygon of the barcode
	Orientation string  // Orientation of the barcode (e.g., ORIENTATION_UP)
}

Symbol represents a detected barcode, including its data, type, polygon, and orientation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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