brother_ql

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 13 Imported by: 0

README

brother-ql : Go pkg for Brother QL label printers

Go Reference

Go port of the popular brother_ql Python package for creating and sending raster instructions to Brother QL-series label printers.

Features

  • Multiple Models Support: Configurable model sizes, compression rules, and features (e.g., QL-500, QL-700, QL-800 series).
  • Multiple Label support: Supports continuous (endless) tapes and pre-cut (die-cut) labels.
  • Image handling: Built-in support for resizing, rotation, and dithering for correct raster formatting.
  • Limited backends: Fully supporting standard network (TCP) and linux_kernel (/dev/usb/lpX) backends without heavy external library dependencies.

Installation

To get the command line tool:

go install github.com/suapapa/go_brother-ql/cmd/brother_ql@latest

To use as a package in your Go application:

go get github.com/suapapa/go_brother-ql

Command Line Interface (CLI)

The CLI aims to replicate the original brother_ql Python toolkit commands.

Global Flags
brother_ql [command]

Flags:
  -b, --backend string   Backends supporting: network, linux_kernel
  -m, --model string     Select target model (e.g., QL-570, QL-820NWB)
  -p, --printer string   Direct connection identifier (tcp://... or file:///...)
Commands
1. Information Helper

List all supported items by the library:

brother_ql info models
brother_ql info labels
brother_ql info env
2. Print a Label

Convert standard PNG or JPEG images into raster streams and print:

# Print with network-connected QL-820NWB
brother_ql -b network -p tcp://192.168.1.50 -m QL-820NWB print -l 62 image.png

# Options for print command:
#   -l, --label string    The label size (e.g., 62, 29, 62red)
#   -r, --rotate string   Rotate image ('auto', 0, 90, 180, 270)
#   -t, --threshold float Threshold value percentage (default 70.0)
#   -d, --dither          Enable dithering
#   -c, --compress        Enable output stream compression
#   --no-cut              Don't cut tape after printing

Code Example

Example of converting an image and writing out using Go API:

package main

import (
	"fmt"
	"image"
	_ "image/png" // import image formats as needed
	"os"

	"github.com/suapapa/go_brother-ql"
)

func main() {
	// 1. Load image
	f, err := os.Open("label.png")
	if err != nil {
		panic(err)
	}
	defer f.Close()
	img, _, err := image.Decode(f)
	if err != nil {
		panic(err)
	}

	// 2. Create printer
	printer, err := brother_ql.NewLabelPrinter("QL-820NWB", "network", "192.168.1.50")
	if err != nil {
		panic(err)
	}
	defer printer.Close()

	// 3. Setup print options
	opts := brother_ql.NewDefaultOptions("62")

	// 4. Print images
	err = printer.Print([]image.Image{img}, opts)
	if err != nil {
		panic(err)
	}
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllLabels []Label

AllLabels contains all predefined label configurations.

View Source
var AllModels []Model

AllModels contains all predefined printer models configurations.

Functions

This section is empty.

Types

type BrotherQLRaster

type BrotherQLRaster struct {
	Model Model
	Data  bytes.Buffer

	CutAtEnd         bool
	Dpi600           bool
	TwoColorPrinting bool
	// contains filtered or unexported fields
}

BrotherQLRaster builds the raster data stream for Brother QL printers.

type Color

type Color int

Color specifies the color capability of the label.

const (
	// BlackWhite is standard black on white printing.
	BlackWhite Color = iota
	// BlackRedWhite is black and red on white printing (two-color).
	BlackRedWhite
)

type ConvertOptions

type ConvertOptions struct {
	Cut        bool
	Dither     bool
	Compress   bool
	Red        bool
	Rotate     string // "auto", "0", "90", "180", "270"
	Dpi600     bool
	Hq         bool
	Threshold  float64
	DitherAlgo string // "atkinson", "burkes", "stucki", "sierra2", "sierra3", "sierralite", "floyd_steinberg"
	OnWarning  func(string)
}

ConvertOptions contains settings for converting images into raster data suitable for the Brother QL printer.

type FormFactor

type FormFactor int

FormFactor specifies the type of label media.

const (
	// DieCut represents die-cut labels with fixed size.
	DieCut FormFactor = iota + 1
	// Endless represents continuous tape labels.
	Endless
	// RoundDieCut represents round die-cut labels.
	RoundDieCut
	// PtouchEndless represents P-touch continuous tape labels.
	PtouchEndless
)

type Label

type Label struct {
	Identifier         string // e.g., "62", "29x90"
	TapeSize           [2]int // width, length in mm
	FormFactor         FormFactor
	DotsTotal          [2]int   // total dots [width, length]
	DotsPrintable      [2]int   // printable dots [width, length]
	OffsetR            int      // right margin alignment offset
	FeedMargin         int      // feed margin in dots
	RestrictedToModels []string // allowed models, if any
	Color              Color
}

Label represents the specifications of a label type.

type LabelPrinter added in v0.1.0

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

LabelPrinter manages connection and printing to a Brother QL printer.

func NewLabelPrinter added in v0.1.0

func NewLabelPrinter(ctx context.Context, model, backend, id string) (*LabelPrinter, error)

NewLabelPrinter creates a new LabelPrinter. It attempts an initial connection but does not return an error if the connection fails (e.g., printer is off), allowing the printer object to be used once it's powered on.

func (*LabelPrinter) Close added in v0.1.4

func (p *LabelPrinter) Close() error

Close closes the connection to the printer after a short delay to allow the printer to process buffered commands.

func (*LabelPrinter) IsLive added in v0.1.5

func (p *LabelPrinter) IsLive(ctx context.Context) bool

IsLive checks if the printer connection is available.

func (*LabelPrinter) Print added in v0.1.0

func (p *LabelPrinter) Print(ctx context.Context, images []image.Image, opts PrintOptions) error

Print converts and sends the images to the printer.

func (*LabelPrinter) Reconnect added in v0.1.5

func (p *LabelPrinter) Reconnect(ctx context.Context) error

Reconnect attempts to re-establish the connection to the printer.

type Model

type Model struct {
	Identifier         string // e.g., "QL-700", "QL-820NWB"
	MinMaxLengthDots   [2]int // [min, max] dots for continuous length
	MinMaxFeed         [2]int // [min, max] feed length
	NumberBytesPerRow  int    // Usually 90 for QL-series, 162 for wider models
	AdditionalOffsetR  int    // Right margin offset
	ModeSetting        bool   // Supports ESC/P and raster mode switching
	Cutting            bool   // Supports automatic cutting
	ExpandedMode       bool   // Supports expanded mode commands
	Compression        bool   // Supports raster line compression
	TwoColor           bool   // Supports Red/Black printing (e.g., QL-800 series)
	NumInvalidateBytes int    // Number of zero bytes to send for invalidation
}

Model describes the capabilities and parameters of a Brother QL printer model.

type PrintOptions added in v0.1.0

type PrintOptions struct {
	Label string // The label size identifier (e.g., "62", "29x90")
	ConvertOptions
}

PrintOptions contains options for printing.

func NewDefaultOptions added in v0.1.0

func NewDefaultOptions(label string) PrintOptions

NewDefaultOptions creates a default PrintOptions with recommended settings.

Directories

Path Synopsis
cmd
brother_ql command

Jump to

Keyboard shortcuts

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