imageproc

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeCacheKey

func ComputeCacheKey(data []byte) string

func ComputeHeight

func ComputeHeight(origW, origH, targetW int) int

func ComputeSrcsetWidths

func ComputeSrcsetWidths(origWidth int) []int

func DecodeImage

func DecodeImage(r *os.File) (image.Image, string, error)

func EncodeJPEG

func EncodeJPEG(img image.Image, quality int) ([]byte, error)

func EncodePNG

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

func EncodeWebP

func EncodeWebP(img image.Image, quality int) ([]byte, error)

EncodeWebP encodes img as a lossy WebP image at the given quality (0-100). Uses a pure-Go VP8 encoder — no cgo, no libwebp dependency.

func GeneratePlaceholder

func GeneratePlaceholder(img image.Image) string

GeneratePlaceholder produces a tiny, blurred, base64-encoded placeholder image used as a low-quality-image placeholder (LQIP) until the real image loads. PNG is used for sources with transparency, JPEG otherwise.

func ParseIntAttr

func ParseIntAttr(val string) int

func ResizeBilinear

func ResizeBilinear(img image.Image, targetW, targetH int) image.Image

Types

type ImageResult

type ImageResult struct {
	// WebP holds the WebP variants (preferred format).
	WebP []SrcsetEntry
	// Fallback holds the original-format variants (JPEG, or PNG when the
	// source has transparency) used by browsers without WebP support.
	Fallback []SrcsetEntry
	// Src is the original source URL used as the <img> fallback (browsers
	// without <picture> support). Set by the caller.
	Src string
	// Width and Height are the display dimensions used for CLS mitigation.
	Width  int
	Height int
	// AspectRatio is the intrinsic ratio (width/height).
	AspectRatio float64
	// FallbackMime is the MIME type of the fallback variants.
	FallbackMime string
	// Placeholder is a base64 data-URI low-quality image placeholder ("" if disabled).
	Placeholder string
}

ImageResult describes the processed image output for a single <Image>.

func ProcessImage

func ProcessImage(root, srcPath string, reqW, reqH, quality int, wantPlaceholder bool) (*ImageResult, error)

type SrcsetEntry

type SrcsetEntry struct {
	Width    int
	FilePath string
}

SrcsetEntry is a single responsive image variant: a URL path + its display width.

Jump to

Keyboard shortcuts

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