christiangeorgelucas/barcode-tools
v0.1.3GoThe barcode-tools package provides composable nodes for generating and decoding various barcode formats including QR codes, Code128, Code39, EAN-13, DataMatrix, and Aztec. It allows developers to easily integrate barcode functionalities into their applications by emitting and consuming image envelopes compatible with image-tools.
Use cases
- •Generate QR codes for product labels
- •Decode barcodes from scanned images
- •Create EAN-13 barcodes for retail products
- •Encode data into DataMatrix for inventory management
- •Utilize Aztec codes for mobile ticketing solutions
Nodes (8)
The AztecEncode node generates an Aztec barcode from ASCII input content and outputs it as a PNG image. It automatically sizes the barcode unless specific dimensions are provided.
View source
package nodes
import (
"context"
"fmt"
"github.com/boombuler/barcode/aztec"
"christiangeorgelucas/barcode-tools/axiom"
gen "christiangeorgelucas/barcode-tools/gen"
)
// AztecEncode renders the input content as an Aztec code and returns it as a PNG
// Image. width/height default to 256x256 when 0.
func AztecEncode(ctx context.Context, ax axiom.Context, input *gen.EncodeInput) (*gen.Image, error) {
if err := checkContent(input.GetContent()); err != nil {
return nil, err
}
if !isASCII(input.GetContent()) {
return nil, fmt.Errorf("AztecEncode supports ASCII content only; non-ASCII payloads are corrupted by the Aztec decoder (use QrEncode or DataMatrixEncode for Unicode)")
}
// minECCPercent=33 (ZXing default), userSpecifiedLayers=0 (auto-size).
bc, err := aztec.Encode([]byte(input.GetContent()), 33, 0)
if err != nil {
return nil, fmt.Errorf("encoding Aztec: %w", err)
}
return renderBarcode(bc, int(input.GetWidth()), int(input.GetHeight()), default2D, default2D)
}
The BarcodeDecode node automatically detects and reads various types of barcodes from an input image, including QR codes, Data Matrix, Aztec, Code 128, Code 39, and EAN-13. It returns the decoded text along with the detected barcode format, or an error if no barcode is found.
View source
package nodes
import (
"context"
"github.com/makiuchi-d/gozxing"
"github.com/makiuchi-d/gozxing/aztec"
"github.com/makiuchi-d/gozxing/datamatrix"
"github.com/makiuchi-d/gozxing/oned"
"github.com/makiuchi-d/gozxing/qrcode"
"christiangeorgelucas/barcode-tools/axiom"
gen "christiangeorgelucas/barcode-tools/gen"
)
// BarcodeDecode auto-detects and reads a barcode from the input image across
// several symbologies (QR, Data Matrix, Aztec, Code 128, Code 39, EAN-13),
// returning the decoded text and detected format. When nothing is found it
// returns a structured result with found=false and an error reason.
func BarcodeDecode(ctx context.Context, ax axiom.Context, input *gen.DecodeInput) (*gen.Decoded, error) {
readers := []gozxing.Reader{
qrcode.NewQRCodeReader(),
datamatrix.NewDataMatrixReader(),
aztec.NewAztecReader(),
oned.NewCode128Reader(),
oned.NewCode39Reader(),
oned.NewEAN13Reader(),
}
return decode(ctx, input, readers)
}
The Code128Encode node generates a Code 128 barcode from the provided input content and outputs it as a PNG image. It allows customization of the barcode's dimensions, defaulting to 300x100 pixels if not specified.
View source
package nodes
import (
"context"
"fmt"
"github.com/boombuler/barcode/code128"
"christiangeorgelucas/barcode-tools/axiom"
gen "christiangeorgelucas/barcode-tools/gen"
)
// Code128Encode renders the input content as a Code 128 barcode and returns it as
// a PNG Image. width/height default to 300x100 when 0.
func Code128Encode(ctx context.Context, ax axiom.Context, input *gen.EncodeInput) (*gen.Image, error) {
if err := checkContent(input.GetContent()); err != nil {
return nil, err
}
bc, err := code128.Encode(input.GetContent())
if err != nil {
return nil, fmt.Errorf("encoding Code 128: %w", err)
}
return renderBarcode(bc, int(input.GetWidth()), int(input.GetHeight()), default1DW, default1DH)
}
The Code39Encode node generates a Code 39 barcode from the provided input content and outputs it as a PNG image. It supports a specific character set and allows for customizable dimensions.
View source
package nodes
import (
"context"
"fmt"
"github.com/boombuler/barcode/code39"
"christiangeorgelucas/barcode-tools/axiom"
gen "christiangeorgelucas/barcode-tools/gen"
)
// Code39Encode renders the input content as a Code 39 barcode and returns it as a
// PNG Image. Content must use the Code 39 charset (uppercase letters, digits, and
// - . $ / + % space). width/height default to 300x100 when 0.
func Code39Encode(ctx context.Context, ax axiom.Context, input *gen.EncodeInput) (*gen.Image, error) {
if err := checkContent(input.GetContent()); err != nil {
return nil, err
}
// includeChecksum=false, fullASCIIMode=false: standard Code 39 that decodes
// back to the exact input via a standard Code 39 reader.
bc, err := code39.Encode(input.GetContent(), false, false)
if err != nil {
return nil, fmt.Errorf("encoding Code 39: %w", err)
}
return renderBarcode(bc, int(input.GetWidth()), int(input.GetHeight()), default1DW, default1DH)
}
The DataMatrixEncode node generates a Data Matrix barcode from the provided input content and outputs it as a PNG image. It allows for customizable dimensions, defaulting to 256x256 pixels if not specified.
View source
package nodes
import (
"context"
"fmt"
"github.com/boombuler/barcode/datamatrix"
"christiangeorgelucas/barcode-tools/axiom"
gen "christiangeorgelucas/barcode-tools/gen"
)
// DataMatrixEncode renders the input content as a Data Matrix code and returns it
// as a PNG Image. width/height default to 256x256 when 0.
func DataMatrixEncode(ctx context.Context, ax axiom.Context, input *gen.EncodeInput) (*gen.Image, error) {
if err := checkContent(input.GetContent()); err != nil {
return nil, err
}
bc, err := datamatrix.Encode(input.GetContent())
if err != nil {
return nil, fmt.Errorf("encoding Data Matrix: %w", err)
}
return renderBarcode(bc, int(input.GetWidth()), int(input.GetHeight()), default2D, default2D)
}
The Ean13Encode node generates an EAN-13 barcode image from a given numeric input, which must be either 12 digits (with the check digit calculated) or 13 digits (with a valid check digit). The output is a PNG image of the barcode, with customizable dimensions.
View source
package nodes
import (
"context"
"fmt"
"github.com/boombuler/barcode/ean"
"christiangeorgelucas/barcode-tools/axiom"
gen "christiangeorgelucas/barcode-tools/gen"
)
// Ean13Encode renders the input content as an EAN-13 barcode and returns it as a
// PNG Image. Content must be 12 digits (the check digit is computed) or 13 digits
// (with a valid check digit). width/height default to 300x100 when 0.
func Ean13Encode(ctx context.Context, ax axiom.Context, input *gen.EncodeInput) (*gen.Image, error) {
if err := checkContent(input.GetContent()); err != nil {
return nil, err
}
bc, err := ean.Encode(input.GetContent())
if err != nil {
return nil, fmt.Errorf("encoding EAN-13 (need 12 or 13 digits): %w", err)
}
return renderBarcode(bc, int(input.GetWidth()), int(input.GetHeight()), default1DW, default1DH)
}
The QrDecode node processes an input image containing a QR code and extracts the encoded text. It returns a structured output indicating the success of the decoding operation along with the decoded content or an error reason if no QR code is found.
View source
package nodes
import (
"context"
"github.com/makiuchi-d/gozxing"
"github.com/makiuchi-d/gozxing/qrcode"
"christiangeorgelucas/barcode-tools/axiom"
gen "christiangeorgelucas/barcode-tools/gen"
)
// QrDecode reads a QR code from the input image (inline data or a url to fetch)
// and returns the decoded text. When no QR code is found it returns a structured
// result with found=false and an error reason, not a failure.
func QrDecode(ctx context.Context, ax axiom.Context, input *gen.DecodeInput) (*gen.Decoded, error) {
return decode(ctx, input, []gozxing.Reader{qrcode.NewQRCodeReader()})
}
The QrEncode node generates a QR code image from the provided input content, utilizing a specified error correction level. It outputs the QR code as a PNG image, with customizable dimensions.
View source
package nodes
import (
"context"
"fmt"
"strings"
"github.com/boombuler/barcode/qr"
"christiangeorgelucas/barcode-tools/axiom"
gen "christiangeorgelucas/barcode-tools/gen"
)
// qrLevel maps an ec_level string ("L","M","Q","H"; default "M") to a QR
// error-correction level.
func qrLevel(s string) (qr.ErrorCorrectionLevel, error) {
switch strings.ToUpper(strings.TrimSpace(s)) {
case "", "M":
return qr.M, nil
case "L":
return qr.L, nil
case "Q":
return qr.Q, nil
case "H":
return qr.H, nil
default:
return qr.M, fmt.Errorf("invalid ec_level %q (want L, M, Q, or H)", s)
}
}
// QrEncode renders the input content as a QR code and returns it as a PNG Image.
// ec_level selects error correction (L/M/Q/H, default M); width/height default to
// 256x256 when 0.
func QrEncode(ctx context.Context, ax axiom.Context, input *gen.EncodeInput) (*gen.Image, error) {
if err := checkContent(input.GetContent()); err != nil {
return nil, err
}
level, err := qrLevel(input.GetEcLevel())
if err != nil {
return nil, err
}
bc, err := qr.Encode(input.GetContent(), level, qr.Auto)
if err != nil {
return nil, fmt.Errorf("encoding QR: %w", err)
}
return renderBarcode(bc, int(input.GetWidth()), int(input.GetHeight()), default2D, default2D)
}
Messages (4)
Download .protoThe ASCII content to be encoded into the Aztec barcode.
The desired width of the output image; defaults to 256 if set to 0.
The desired height of the output image; defaults to 256 if set to 0.
The error correction level for the QR code, which can be 'L', 'M', 'Q', or 'H'.
The desired width of the output image; defaults to 256 if set to 0.
The desired height of the output image; defaults to 256 if set to 0.
Use as a tool in any AI agent
christiangeorgelucas/barcode-tools is callable as a tool from any MCP client (Claude, Cursor, or your own agent) via Axiom's hosted MCP server — no install, no download. Add the server, then your agent can search and invoke it, or pin it as a typed tool.
claude mcp add --transport http axiom https://api.axiomide.com/mcp --header "Authorization: Bearer YOUR_AXIOM_API_KEY"Replace YOUR_AXIOM_API_KEY with a key you create in Console → API Keys.
MCP server setup & other clients →Use this package
Sign in to import christiangeorgelucas/barcode-tools into the graph editor — drop it into a flow and hit run. Or call it directly via the API Reference with your API key.
Sign in to useOpen editor