qr

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseColor added in v0.3.0

func ParseColor(s string) (color.Color, error)

ParseColor converts a user-supplied color string into a color.Color.

Accepted forms (case-insensitive, leading '#' optional):

#rgb          shorthand hex (each digit doubled: f → ff)
#rrggbb       standard hex
#rrggbbaa     hex with straight alpha
<name>        black, white, red, green, blue, yellow, cyan, magenta, transparent

The returned Color is a color.NRGBA (straight alpha), which preserves the user's intent under downstream compositing regardless of the consumer.

func RenderTerminal

func RenderTerminal(w io.Writer, qr *qrcode.QRCode, cfg TerminalConfig)

RenderTerminal renders a QR code to the terminal

func SavePNG

func SavePNG(qr *qrcode.QRCode, filename string, size int) error

SavePNG saves the QR code as a PNG file

func SavePNGWithLogo(qr *qrcode.QRCode, filename string, size int, opts LogoOptions) error

SavePNGWithLogo writes the QR code as a PNG with a logo composited at center. The caller should generate the QR code with error correction level H so the masked modules can still be recovered during scanning.

func SaveSVG

func SaveSVG(qr *qrcode.QRCode, filename string, size int) error

SaveSVG writes the QR code as an SVG file. size is the rendered pixel size; the SVG is square (size x size).

func ToBase64

func ToBase64(qr *qrcode.QRCode, size int) (string, error)

ToBase64 returns the QR code as a base64-encoded PNG string

func ToSVG

func ToSVG(qr *qrcode.QRCode, size int) []byte

ToSVG renders the QR code to an SVG byte slice. The bitmap from skip2/go-qrcode already includes the standard quiet zone. ForegroundColor / BackgroundColor on qr are honored; a fully-transparent background omits the background rect so the QR sits on page transparency.

Types

type ErrorCorrectionLevel

type ErrorCorrectionLevel int

ErrorCorrectionLevel represents QR code error correction level

const (
	LevelL ErrorCorrectionLevel = iota // 7% recovery
	LevelM                             // 15% recovery
	LevelQ                             // 25% recovery
	LevelH                             // 30% recovery
)

func ParseLevel

func ParseLevel(s string) (ErrorCorrectionLevel, error)

ParseLevel parses a string into ErrorCorrectionLevel

type Generator

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

Generator creates QR codes

func NewGenerator

func NewGenerator(opts Options) *Generator

NewGenerator creates a new QR code generator

func (*Generator) Generate

func (g *Generator) Generate(content string) (*qrcode.QRCode, error)

Generate creates a QR code from content

func (*Generator) GeneratePNG

func (g *Generator) GeneratePNG(content string) ([]byte, error)

GeneratePNG generates a QR code and returns it as PNG bytes

type LogoOptions

type LogoOptions struct {
	// LogoPath is the filesystem path to the logo image (PNG, JPEG, or GIF).
	LogoPath string
	// SizeRatio is logo edge length as a fraction of QR size (default 0.20).
	// Values above 0.35 are rejected: the QR typically becomes unscannable.
	SizeRatio float64
	// PadRatio is the white padding around the logo as a fraction of logo size (default 0.10).
	PadRatio float64
}

LogoOptions configures logo embedding into a QR code.

func DefaultLogoOptions

func DefaultLogoOptions(logoPath string) LogoOptions

DefaultLogoOptions returns sensible defaults for a given logo path.

type Options

type Options struct {
	Level           ErrorCorrectionLevel
	Size            int
	ForegroundColor color.Color
	BackgroundColor color.Color
}

Options configures QR code generation

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns default QR generation options

type OutputFormat

type OutputFormat string

OutputFormat represents the output format

const (
	FormatTerminal OutputFormat = "terminal"
	FormatPNG      OutputFormat = "png"
	FormatSVG      OutputFormat = "svg"
	FormatBase64   OutputFormat = "base64"
)

func DetectFormat

func DetectFormat(filename string) OutputFormat

DetectFormat detects output format from filename

type TerminalConfig

type TerminalConfig struct {
	Invert bool // Invert colors for dark terminals
	Small  bool // Use half-block characters for compact output
}

TerminalConfig configures terminal output

Jump to

Keyboard shortcuts

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