Documentation
¶
Index ¶
- func ParseColor(s string) (color.Color, error)
- func RenderTerminal(w io.Writer, qr *qrcode.QRCode, cfg TerminalConfig)
- func SavePNG(qr *qrcode.QRCode, filename string, size int) error
- func SavePNGWithLogo(qr *qrcode.QRCode, filename string, size int, opts LogoOptions) error
- func SaveSVG(qr *qrcode.QRCode, filename string, size int) error
- func ToBase64(qr *qrcode.QRCode, size int) (string, error)
- func ToSVG(qr *qrcode.QRCode, size int) []byte
- type ErrorCorrectionLevel
- type Generator
- type LogoOptions
- type Options
- type OutputFormat
- type TerminalConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseColor ¶ added in v0.3.0
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 SavePNGWithLogo ¶
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 ¶
SaveSVG writes the QR code as an SVG file. size is the rendered pixel size; the SVG is square (size x size).
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 ¶
NewGenerator creates a new QR code generator
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