logo

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package logo provides image loading, resizing, tinting, and overlay compositing for QR code center logo images.

The package supports PNG, JPEG, and GIF formats and exposes both a Processor type for fluent logo manipulation and standalone functions for individual operations.

Typical Pipeline

proc := logo.New("logo.png", 0.25).WithTint(color.RGBA{0, 0, 0, 255})
img, err := proc.Load()
resized := logo.ResizeLogo(img, qrModules, 0.25)
tinted := logo.TintLogo(resized, color.RGBA{0, 0, 0, 255})
final := logo.OverlayLogo(qrImage, tinted, qrModules)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneToRGBA

func CloneToRGBA(img image.Image) *image.RGBA

CloneToRGBA copies any image into a new *image.RGBA using source-over compositing. This is useful for normalizing image types before further processing.

func EncodePNG

func EncodePNG(img image.Image) ([]byte, error)

EncodePNG encodes an image as PNG bytes suitable for writing to a file or sending in an HTTP response.

func IsSupportedFormat

func IsSupportedFormat(ext string) bool

IsSupportedFormat reports whether the file extension (with or without a leading dot) is a supported image format. The check is case-insensitive.

func LoadFromBytes

func LoadFromBytes(data []byte) (image.Image, error)

LoadFromBytes decodes an image from raw bytes. Supports PNG, JPEG, and GIF formats via Go's standard image decoders.

func LoadFromReader

func LoadFromReader(r io.Reader) (image.Image, error)

LoadFromReader decodes an image from an io.Reader. Supports PNG, JPEG, and GIF formats via Go's standard image decoders.

func LogoSize

func LogoSize(qrPixelSize int, ratio float64) int

LogoSize calculates the logo pixel size from the QR code pixel size and the desired ratio. The result is clamped to a minimum of 1.

func OverlayLogo(qrImage, logoImg image.Image, _ int) *image.RGBA

OverlayLogo composites the logo onto the center of the QR code image using alpha blending. The QR code image is used as the base and the logo is drawn on top. Returns a new *image.RGBA with the composited result.

func ResizeLogo(img image.Image, qrModules int, ratio float64) *image.RGBA

ResizeLogo resizes the logo to fit within the QR code based on the ratio of the QR module count. The aspect ratio of the original image is preserved. The result is an *image.RGBA.

func ResizeLogoToPixels

func ResizeLogoToPixels(img image.Image, width, height int) *image.RGBA

ResizeLogoToPixels resizes the logo to the exact pixel dimensions specified by width and height. Values less than 1 are clamped to 1.

func SupportedFormats

func SupportedFormats() []string

SupportedFormats returns the list of supported image file extensions (including the leading dot).

func TintLogo(img image.Image, tint color.Color) *image.RGBA

TintLogo applies a multiplicative color tint to the logo image. Each pixel's RGBA components are multiplied with the corresponding tint components. Pass nil for tint to simply clone the image.

func Validate

func Validate(path string) error

Validate checks that the logo file at path exists, is a regular file (not a directory), and has a supported image format extension.

Types

type Processor

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

Processor loads and manipulates a logo image for QR code overlay.

Create a Processor with New and optionally chain Processor.WithTint. Use Processor.Load to read the image from disk.

func New

func New(source string, sizeRatio float64) *Processor

New creates a new Processor for the logo at source with the given size ratio. The sizeRatio determines how much of the QR code the logo will occupy (e.g., 0.25 = 25%).

func (*Processor) Load

func (p *Processor) Load() (image.Image, error)

Load reads and decodes the logo image from the source path. Returns an error if the source is empty, the file cannot be opened, or the image format cannot be decoded.

func (*Processor) SizeRatio

func (p *Processor) SizeRatio() float64

SizeRatio returns the logo size ratio as a fraction of the QR code size.

func (*Processor) Source

func (p *Processor) Source() string

Source returns the logo source file path.

func (*Processor) WithTint

func (p *Processor) WithTint(c color.Color) *Processor

WithTint sets a color tint to be applied during processing. Returns the receiver for method chaining. Pass nil to clear any previously set tint.

Jump to

Keyboard shortcuts

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