qrscan

package module
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

QR Code & Barcode Scanner for Go

Ask AI

ChatGPT Claude Gemini Grok Perplexity Copilot DeepSeek Meta AI Qwen

Choose an AI assistant to explain this destination using its public sources. Gemini opens gemini.google.com. Gemini, Copilot, DeepSeek, Meta AI and Qwen require pasting the prompt below; the other links include it in their URL. Sign-in or a manual paste may still be required. Check the answer against the documentation.

Copy the plain-text prompt

Use the code block's copy control, or select its complete text, then paste it into your assistant.

Help me understand QR Code & Barcode Scanner for Go (bindings/go/README.md) for QR Code & Barcode Scanner, the open-source scanner. Source documentation; publication is not implied. Provided README context (verify against the sources): Use the Go adapter in an existing Go service, batch job or command that can start a local process. Install qrscan separately and keep its version compatible with the adapter. The adapter forwards the engine report rather than translating identifiers into numbers, which matters for barcode values with leading zeroes. Read the public documentation below. Explain what this destination does, its documented installation or access steps, a minimal example if supported, prerequisites, limitations and license. Distinguish published packages from working source and preparation. Cite your sources; if a page is unavailable or a fact cannot be checked, say so. Do not invent installation commands, benchmark results or comparisons. Answer in my language. Public sources: https://github.com/qrcode-ai-com/qrcode-barcode-scanner-rust/blob/main/bindings/go/README.md https://qrcode-ai.com/en-US/qr-code-scanner https://qrcode-ai.com/en-US/barcode-scanner https://qrcode-ai.com/en-US/qr-code-scanner/sdk/go https://qrcode-ai.com/en-US/barcode-scanner/sdk/go https://qrcode-ai.com/en-US/qr-code-generator https://qrcode-ai.com/en-US/barcode-generator

Use the Go adapter in an existing Go service, batch job or command that can start a local process. Install qrscan separately and keep its version compatible with the adapter. The adapter forwards the engine report rather than translating identifiers into numbers, which matters for barcode values with leading zeroes.

The QR code scanner and barcode scanner are QR Code AI’s browser scanning entry points. For the corresponding development route, the QR code scanner Go guide and barcode scanner Go guide connect this documentation to the two product journeys. If a product page is unavailable, the instructions and references in this README remain the starting point for this source directory.

To prepare a zero-prefixed reference for a Go import test, use the QR code generator or the barcode generator. Keep the original payload with the exported image so that you can compare the scan result with the value you intended to encode.

Read QR codes and barcodes from an image file in Go. This package drives the installed qrscan command of the QR Code & Barcode Scanner engine and returns its JSON report unchanged. It holds no decoder of its own, uses the standard library only and needs no cgo.

How it works

The picture shows the three steps. Your code passes the path of an image file, the installed qrscan command reads its codes, and your code reads the JSON report it returns. The next sections follow that order: install the package and qrscan, scan an image, then read the report.

Install

go get github.com/qrcode-ai-com/qrcode-barcode-scanner-go@v0.12.3
import qrscan "github.com/qrcode-ai-com/qrcode-barcode-scanner-go"

The package follows the engine it drives: version 0.12.x of the package works with qrscan 0.12.x. The first version is 0.11.0.

What you need

  • Go 1.24 or later. CGO_ENABLED=0 works: there is no C code.
  • The qrscan command, version 0.12.x, installed separately. The distribution guide lists the routes: Homebrew, Scoop, the Debian and RPM packages, the AUR, cargo install, the release archives and the container image. This package never downloads it.

Install qrscan from the channel your system already uses:

Channel Install Systems
Homebrew brew install qrcode-ai-com/tap/qrscan macOS and GNU/Linux
Scoop scoop bucket add qrcode-ai https://github.com/qrcode-ai-com/scoop-bucket
scoop install qrcode-ai/qrcode-barcode-scanner
Windows x64
Cargo cargo install qrcode-barcode-scanner-cli --locked Any Rust toolchain
Releases Download and verify an archive macOS, GNU/Linux, Windows
Debian Install the .deb package Debian 12, Ubuntu 24.04
AUR Arch install guide Arch Linux x86_64
Fedora Install the RPM package Fedora 44
AppImage Run the AppImage, one file with nothing to install GNU/Linux
Container image ghcr.io/qrcode-ai-com/qrcode-barcode-scanner, run as the container guide shows Linux AMD64 and ARM64

Scan an image

scanner := qrscan.New("") // qrscan on PATH; or qrscan.New("/path/to/qrscan")
report, err := scanner.Scan(ctx, "label.png", qrscan.Fast, qrscan.ProfileBudget)
if err != nil {
	return err
}
for _, detection := range report.Detections {
	fmt.Println(detection.Symbology, detection.Text)
}

Scan takes a context, the file, a profile and a time budget in milliseconds:

Profile What the engine does
qrscan.Frame Decodes only. The report carries no score.
qrscan.Fast Decodes first, with a reduced judgment.
qrscan.Full Decodes and judges how well a QR code scans.

qrscan.ProfileBudget keeps the profile's own budget, and a busy machine can then cut the scan short. qrscan.Unbounded sets none: the result then does not depend on how busy the machine is. Cancelling the context stops the command.

Read the report

A QR code and Code 128 decoded from the same image, each outlined where the engine measured it

The picture is a recorded scan of one image that holds a QR code and a Code 128 barcode. Both come back in the same report, each with its format and the place where the engine measured it.

report.JSON is the exact text the engine printed. Nothing is renamed, rounded or recalculated, so decode it yourself for the payload, the measured places and the trace. The other fields read the most used parts:

Field Meaning
Found() At least one code was decoded.
Detections One entry per distinct content: Symbology, Text and Raw, the exact bytes.
Score The scannability judgment, or nil.
Complete false when the time budget cut the scan.
EngineVersion The engine that wrote the report, such as 0.11.0.

Three things are easy to get wrong:

  • No code is a result, not an error. Found() is false and err is nil.
  • A missing score is not zero. Score is nil with qrscan.Frame, or when the budget ran out before the judgment.
  • An incomplete scan proves nothing. When Complete is false, an empty report does not mean the image holds no code. Scan again with a larger budget or with qrscan.Unbounded.

Decoded text is untrusted data: a QR code can hold any text. Do not follow its links or run it.

What it reads

The package returns the report of the qrscan command you installed, so it reads what that engine reads. Codes of different formats in the same image come back in one report.

Family Formats
QR QR Code, Micro QR, rectangular Micro QR (rMQR)
Matrix and stacked Data Matrix, Aztec, PDF417, MaxiCode
Retail EAN-13, EAN-8, UPC-A, UPC-E
Other linear Code 128, Code 39, Code 93, Codabar, ITF, GS1 DataBar, GS1 DataBar Expanded, Telepen

The engine's supported formats section states the known limits.

When something fails

Error When
qrscan.ErrBinaryNotFound (with errors.Is) qrscan could not be started: not installed, not on PATH, not executable. It is not remembered: install the command and the same Scanner works.
*qrscan.UnsupportedVersionError The installed qrscan is not 0.12.x. The check runs before the first scan.
*qrscan.ScanError The engine refused the file or the options. EngineCode holds its code when it gives one, such as QRS-001 for a file that is not an image.
the context's error The context was cancelled or its deadline passed; the command was stopped.

What it does and does not do

  • One scan starts one process. That suits a request or a job. It is the wrong tool for thousands of images in a tight loop.
  • It reads image files: PNG, JPEG, WebP and GIF. To scan bytes you hold in memory, write them to a temporary file first.
  • The command is started from a list of arguments, with no shell. A file name is never interpreted, whatever it holds: spaces, quotes, a leading dash or shell characters.
  • It writes nothing, fetches nothing and never opens what a code points to.

Why not WebAssembly

A first experiment compiled the engine to WebAssembly and ran it inside the Go process with wazero. Its reports were identical to the native command's, and one scan of a photo-sized image took about twenty times longer. The owner chose this route on 11 November 2026.

Develop

The tests run against a real qrscan, not a stand-in:

QRSCAN_BINARY=/path/to/qrscan QRSCAN_FIXTURES=/path/to/engine/fixtures go test ./...

They cover the three profiles on an image that holds a QR code and a Code 128, an image with no code, files that are not images, awkward file names, a missing command, an engine of another version and a cancelled context. The workflow Go adapter of the engine repository runs them on Linux, macOS and Windows against the released command.

The same engine in other runtimes

Runtime Package How it scans
Rust qrcode-barcode-scanner on crates.io In process
Node.js @qrcode-ai-com/qrcode-barcode-scanner on npm In process, native
Browser @qrcode-ai-com/qrcode-barcode-scanner-wasm on npm In the page, WebAssembly
Python qrcode-barcode-scanner on PyPI In process
Go qrcode-barcode-scanner-go Through the installed qrscan
PHP qrcode-barcode-scanner-php Through the installed qrscan
Command line qrscan One command, one JSON report

The Rust, Node.js, browser and Python packages hold the engine. The Go and PHP packages hold no decoder: each one starts qrscan and hands you its report.

Language and platform names and logos belong to their owners. They identify a runtime or a destination and imply no endorsement.

Its own repository

A Go module is fetched from the root of a repository at a tag, so the package is served from a small repository of its own, qrcode-ai-com/qrcode-barcode-scanner-go. Nothing there is edited by hand: scripts/stage-go-package.py writes its whole tree from one commit of the engine repository, with the workflow of mirror/, the two test images, the licence and a SOURCE.json that names the commit and the sha256 of every file. The same program checks that a tree is exactly that. Change the package here, then stage it again.

Licence

Project-authored adapter source is MIT; see LICENSE. The separately installed engine retains the license of its exact installed version.

Maintained by Thibaut Mélen & Nicolas Cella for QR Code AI, a product of SuperNovae Studio. The license of each component is stated in its own license files.

Source license

Project-authored scanner code and documentation in this checkout are available under the MIT License. You may use, modify and redistribute this source in open-source or proprietary applications, including commercial products, while preserving the copyright and permission notice. Thibaut Mélen & Nicolas Cella develop QR Code AI at SuperNovae Studio.

Retained third-party code, dependencies, artwork and test data keep their own licenses and notices. The licensing guide explains these component boundaries; the project license does not assign a license to an unrelated platform or service.

Published archives retain the license shipped with their version. A pinned engine, adapter or bundle may therefore have different terms from this working source. Read its packaged license and the license history before reuse. The source change does not replace an archive or publish a new version.

Documentation

Overview

Package qrscan reads QR codes and barcodes from an image file through the installed qrscan command of the QR Code & Barcode Scanner engine.

The package holds no decoder. It starts the command, which you install separately, and returns its JSON report unchanged. One scan is one process. The command is started from a list of arguments, with no shell: a file name is never interpreted, whatever it holds. The package uses the standard library only, with no cgo.

scanner := qrscan.New("") // qrscan on PATH
report, err := scanner.Scan(ctx, "label.png", qrscan.Fast, qrscan.ProfileBudget)
for _, detection := range report.Detections {
	fmt.Println(detection.Symbology, detection.Text)
}

Index

Constants

View Source
const (
	// ProfileBudget keeps the profile's own budget.
	ProfileBudget = -1
	// Unbounded sets no budget: the result then does not depend on how busy the machine is.
	Unbounded = 0
)

A time budget for the engine, in milliseconds.

View Source
const SupportedEngine = "0.12"

SupportedEngine is the engine line this package was checked against: every 0.12.x.

Variables

View Source
var ErrBinaryNotFound = errors.New("qrscan: the qrscan command could not be started")

ErrBinaryNotFound means the qrscan command could not be started: it is not installed, not on PATH or not executable.

Functions

This section is empty.

Types

type Detection

type Detection struct {
	// Symbology is the kind of code, such as qr_code or code128.
	Symbology string
	// Text is the decoded text. Treat it as untrusted data: a QR code can hold any text.
	Text string
	// Raw is the exact bytes of the content, for content that is not text.
	Raw []byte
}

Detection is one decoded content. The full entry, with its payload and measured places, is in Report.JSON.

type Profile

type Profile string

Profile says how much work one scan does. The values are the ones `qrscan --profile` takes.

const (
	// Full decodes and judges how well a QR code scans.
	Full Profile = "full"
	// Fast decodes first, with a reduced judgment.
	Fast Profile = "fast"
	// Frame decodes only: the report carries no score.
	Frame Profile = "frame"
)

type Report

type Report struct {
	// JSON is the engine's report, exactly as printed.
	JSON []byte
	// ExitCode is 0 when qrscan found a code and 1 when it found none.
	ExitCode int
	// Detections holds one entry per distinct content.
	Detections []Detection
	// Score is nil when the engine made no judgment: the frame profile, or a budget that ran
	// out. Nil is never zero.
	Score *Score
	// Complete is false when the time budget cut the scan: an empty report then proves nothing.
	Complete bool
	// EngineVersion is the engine that wrote the report, such as 0.11.0.
	EngineVersion string
}

Report is one scan report. JSON is the text the engine printed, unchanged: nothing is renamed, rounded or recalculated. The other fields only read it. A report with no detection is a valid result, not an error.

func (*Report) Found

func (r *Report) Found() bool

Found reports whether at least one code was decoded.

type ScanError

type ScanError struct {
	// ExitCode is the command's exit code.
	ExitCode int
	// EngineCode is the engine's own code, such as QRS-001 for a file that is not an image.
	// It is empty when the message carries none.
	EngineCode string
	// Message is one line of the command's own message.
	Message string
}

ScanError means the engine refused the file or the options, or its output could not be read.

func (*ScanError) Error

func (e *ScanError) Error() string

type Scanner

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

Scanner starts one qrscan command. It is safe for concurrent use.

func New

func New(binary string) *Scanner

New returns a Scanner for the given command: a name looked up on PATH or a path. An empty name means "qrscan".

func (*Scanner) Capabilities

func (s *Scanner) Capabilities(ctx context.Context) ([]byte, error)

Capabilities returns what the installed command can read, as the JSON it printed: its versions, decode engines and symbologies.

func (*Scanner) EngineVersion

func (s *Scanner) EngineVersion(ctx context.Context) (string, error)

EngineVersion returns the version of the installed engine, such as 0.11.0. It fails with UnsupportedVersionError when that version is outside the supported line.

func (*Scanner) Scan

func (s *Scanner) Scan(ctx context.Context, imagePath string, profile Profile, budgetMs int) (*Report, error)

Scan reads the codes of one image file (PNG, JPEG, WebP or GIF). budgetMs is ProfileBudget, Unbounded or a number of milliseconds. Cancelling ctx stops the command.

type Score

type Score struct {
	// Value is the composite score, from 0 to 100.
	Value int
}

Score is the scannability judgment of a QR code.

type UnsupportedVersionError

type UnsupportedVersionError struct {
	// Version is what the command reported, empty when it reported none.
	Version string
}

UnsupportedVersionError means the installed qrscan is not a version this package was checked against.

func (*UnsupportedVersionError) Error

func (e *UnsupportedVersionError) Error() string

Jump to

Keyboard shortcuts

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