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 ¶
- func CloneToRGBA(img image.Image) *image.RGBA
- func EncodePNG(img image.Image) ([]byte, error)
- func IsSupportedFormat(ext string) bool
- func LoadFromBytes(data []byte) (image.Image, error)
- func LoadFromReader(r io.Reader) (image.Image, error)
- func LogoSize(qrPixelSize int, ratio float64) int
- func OverlayLogo(qrImage, logoImg image.Image, _ int) *image.RGBA
- func ResizeLogo(img image.Image, qrModules int, ratio float64) *image.RGBA
- func ResizeLogoToPixels(img image.Image, width, height int) *image.RGBA
- func SupportedFormats() []string
- func TintLogo(img image.Image, tint color.Color) *image.RGBA
- func Validate(path string) error
- type Processor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloneToRGBA ¶
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 ¶
EncodePNG encodes an image as PNG bytes suitable for writing to a file or sending in an HTTP response.
func IsSupportedFormat ¶
IsSupportedFormat reports whether the file extension (with or without a leading dot) is a supported image format. The check is case-insensitive.
func LoadFromBytes ¶
LoadFromBytes decodes an image from raw bytes. Supports PNG, JPEG, and GIF formats via Go's standard image decoders.
func LoadFromReader ¶
LoadFromReader decodes an image from an io.Reader. Supports PNG, JPEG, and GIF formats via Go's standard image decoders.
func LogoSize ¶
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 ¶
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 ¶
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 ¶
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).
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 ¶
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 ¶
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 ¶
SizeRatio returns the logo size ratio as a fraction of the QR code size.