Read saved QR images
Pass an image file path (PNG, JPEG, WebP or GIF) to scanner.Scan() to get decoded QR text, raw bytes and score.
pkg.go.dev
Zero cgo
Uses qrscan
MIT
Drive the native qrscan binary using Go’s standard library with context cancellation and zero C compilation.
Pass an image file path (PNG, JPEG, WebP or GIF) to scanner.Scan() to get decoded QR text, raw bytes and score.
Compiles cleanly with CGO_ENABLED=0 and invokes the installed qrscan binary directly without a shell so arbitrary filenames stay safe.
Inspect report.Found(), Detections, Score, Complete and report.JSON (unmodified engine output) with typed Go error handling.
Install the Go module alongside the qrscan CLI, then decode an image file with a Go context.
Requires Go 1.24 or newer and the Go module on pkg.go.dev. Install the matching QR Code Scanner CLI binary separately via Homebrew, Scoop, Cargo, Debian/RPM, AUR, AppImage, GitHub Releases or a container image.
The Go module embeds no decoder of its own and never downloads qrscan at runtime. Keeping both on the same release line satisfies the startup version check.
go get github.com/qrcode-ai-com/qrcode-barcode-scanner-go@v0.12.2
CGO_ENABLED=0 works out of the box because the adapter contains zero C code.
Pass an explicit path to qrscan.New("/path/to/qrscan") whenever qrscan is not on PATH.
Create a scanner via qrscan.New(""), call scanner.Scan with a context, profile and budget, and keep detections whose Symbology is qr_code. Cancelling ctx terminates the qrscan subprocess cleanly.
package main
import (
"context"
"fmt"
qrscan "github.com/qrcode-ai-com/qrcode-barcode-scanner-go"
)
func readQRImage(ctx context.Context, path string) ([]string, error) {
scanner := qrscan.New("")
report, err := scanner.Scan(ctx, path, qrscan.Full, qrscan.ProfileBudget)
if err != nil {
return nil, err
}
if !report.Complete {
return nil, fmt.Errorf("scan budget cut before completion")
}
var urls []string
for _, d := range report.Detections {
if d.Symbology == "qr_code" {
urls = append(urls, d.Text)
}
}
return urls, nil
}
Choose qrscan.Frame (decode only, nil Score), qrscan.Fast (lighter scoring) or qrscan.Full (full QR quality assessment).
Use qrscan.Unbounded instead of qrscan.ProfileBudget when you want reproducible scans independent of host CPU load.
For a QR image encoding https://qrcode-ai.com/, readQRImage returns []string{"https://qrcode-ai.com/"}. Read report.JSON whenever you need the full, unmodified engine JSON covering geometry, payloads and trace.
No code found is a normal outcome: report.Found() is false and err is nil. Branch on qrscan.ErrBinaryNotFound (via errors.Is), *qrscan.UnsupportedVersionError, *qrscan.ScanError (EngineCode such as QRS-001) or the context error.
One process per scan. Each Scan() call runs qrscan directly from an argument slice without invoking a shell, so paths containing spaces, quotes or leading dashes are never interpreted. This suits HTTP request handlers and batch jobs rather than tight loops over thousands of frames.
File input and why not WASM. Supply PNG, JPEG, WebP or GIF file paths (write in-memory uploads to a temp file first). Running the native qrscan binary avoids the roughly twentyfold slowdown observed in earlier wazero WebAssembly trials.
Untrusted payloads and licence. Treat decoded text as untrusted data and never open URLs automatically. Project-authored adapter source is MIT-licensed; see the Go adapter README and Go module GitHub repository.
Official package guides, ScanReport specification and licensing references.
cgo, qrscan prerequisite, contexts, budgets, errors, offline use and licensing.
It is QR Code AI’s open-source MIT-licensed Go module (github.com/qrcode-ai-com/qrcode-barcode-scanner-go) that drives a separately installed qrscan binary using only the Go standard library and returns the ScanReport unchanged.
No. It requires Go 1.24 or newer, depends solely on the standard library and compiles cleanly with CGO_ENABLED=0. You only need the native qrscan binary installed on your host or baked into your container image.
An earlier trial running the engine inside Go via wazero yielded identical reports but ran roughly twenty times slower on photo-sized images. Driving native qrscan keeps native speed with zero cgo overhead.
Scan() accepts a file path (PNG, JPEG, WebP or GIF), so write in-memory uploads to a temporary file first. Because each scan launches a qrscan subprocess, it suits request handlers and batch jobs; for high-throughput in-process loops, use the Rust, Node.js, Python or .NET bindings.
When no code is present, report.Found() is false and err is nil. If report.Complete is false, the budget cut scanning short so an empty result is not final; retry with qrscan.Unbounded. Hard failures return ErrBinaryNotFound, *UnsupportedVersionError, *ScanError (with EngineCode) or ctx.Err().
Yes. The adapter executes qrscan from an explicit argument slice without invoking a shell, so spaces, quotes, leading dashes and shell metacharacters in file paths are never interpreted.
No. The adapter writes nothing, makes zero network calls and never fetches decoded URLs. Decoding executes entirely locally on your host or container with no QR Code AI account or API key.
Yes. Current releases of the Go adapter and qrscan engine ship under the MIT licence for commercial and proprietary services provided copyright and licence notices are preserved (see LICENSING.md). SDK use is separate from QR Code AI’s paid creation plans and seven-day Premium trial.