Skip to content

makiuchi-d/gozxing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gozxing A Barcode Scanning/Encoding Library for Go

Build Status codecov

ZXing is an open-source, multi-format 1D/2D barcode image processing library for Java. This project is a port of ZXing core library to pure Go.

Porting Status (supported formats)

2D barcodes

Format Scanning Encoding
QR Code ✔️ ✔️
Data Matrix ✔️ ✔️
Aztec ✔️
PDF 417
MaxiCode

1D product barcodes

Format Scanning Encoding
UPC-A ✔️ ✔️
UPC-E ✔️ ✔️
EAN-8 ✔️ ✔️
EAN-13 ✔️ ✔️

1D industrial barcode

Format Scanning Encoding
Code 39 ✔️ ✔️
Code 93 ✔️ ✔️
Code 128 ✔️ ✔️
Codabar ✔️ ✔️
ITF ✔️ ✔️
RSS-14 ✔️ -
RSS-Expanded

Special reader/writer

Reader/Writer Porting status
MultiFormatReader
MultiFormatWriter
ByQuadrantReader
GenericMultipleBarcodeReader
QRCodeMultiReader ✔️
MultiFormatUPCEANReader ✔️
MultiFormatOneDReader

Usage Examples

Scanning QR code

package main

import (
	"fmt"
	"image"
	_ "image/jpeg"
	"os"

	"github.com/makiuchi-d/gozxing"
	"github.com/makiuchi-d/gozxing/qrcode"
)

func main() {
	// open and decode image file
	file, _ := os.Open("qrcode.jpg")
	img, _, _ := image.Decode(file)

	// prepare BinaryBitmap
	bmp, _ := gozxing.NewBinaryBitmapFromImage(img)

	// decode image
	qrReader := qrcode.NewQRCodeReader()
	result, _ := qrReader.Decode(bmp, nil)

	fmt.Println(result)
}

Generating CODE128 barcode

package main

import (
	"image/png"
	"os"

	"github.com/makiuchi-d/gozxing"
	"github.com/makiuchi-d/gozxing/oned"
)

func main() {
	// Generate a barcode image (*BitMatrix)
	enc := oned.NewCode128Writer()
	img, _ := enc.Encode("Hello, Gophers!", gozxing.BarcodeFormat_CODE_128, 250, 50, nil)

	file, _ := os.Create("barcode.png")
	defer file.Close()

	// *BitMatrix implements the image.Image interface,
	// so it is able to be passed to png.Encode directly.
	_ = png.Encode(file, img)
}