Documentation
¶
Index ¶
- func ComputeCacheKey(data []byte) string
- func ComputeHeight(origW, origH, targetW int) int
- func ComputeSrcsetWidths(origWidth int) []int
- func DecodeImage(r *os.File) (image.Image, string, error)
- func EncodeJPEG(img image.Image, quality int) ([]byte, error)
- func EncodePNG(img image.Image) ([]byte, error)
- func EncodeWebP(img image.Image, quality int) ([]byte, error)
- func GeneratePlaceholder(img image.Image) string
- func ResizeBilinear(img image.Image, targetW, targetH int) image.Image
- type ImageResult
- type SrcsetEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeCacheKey ¶
func ComputeHeight ¶
func ComputeSrcsetWidths ¶
func EncodeWebP ¶
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 ¶
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.
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 ¶
SrcsetEntry is a single responsive image variant: a URL path + its display width.
Click to show internal directories.
Click to hide internal directories.