Documentation
¶
Overview ¶
Package imagex provides image decode/resize/encode helpers and an opt-in responsive-image pipeline for SSR pages and uploads.
Supports JPEG/PNG encode via the standard library, WebP decode via golang.org/x/image/webp, and WebP encode via the pure-Go github.com/deepteams/webp library (no CGO).
Transform is the primitive. Pipeline mounts GET /_irmik/img plus an {{ img }} template helper (frontend SSR). Variants / WriteVariants encode allowlisted widths at upload time (admin). Nothing here is wired by irmik.New.
Opt-in: import only when processing images.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultWidths = []int{375, 768, 1440}
DefaultWidths is the allowlist used when Pipeline.Widths is empty.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// MaxWidth / MaxHeight constrain dimensions (preserving aspect). 0 = unlimited.
MaxWidth int
MaxHeight int
Format Format
// Quality for JPEG/WebP (1-100, default 85).
Quality int
}
Options controls resize/encode.
type Pipeline ¶ added in v0.1.1
type Pipeline struct {
// Root is the filesystem root for source images (e.g. "./public").
Root string
// Path is the handler route (default /_irmik/img).
Path string
// Widths is the allowlist of srcset widths (default 375, 768, 1440).
Widths []int
// Format is the encoded variant format (default WEBP).
Format Format
// Quality for JPEG/WebP (default 80).
Quality int
// CacheDir, when set, stores encoded variants on disk.
CacheDir string
// MaxSourceBytes caps a source file (default 8 MiB).
MaxSourceBytes int64
// contains filtered or unexported fields
}
Pipeline is an opt-in responsive image optimizer.
Mount it on the Gin engine and merge FuncMap into MountPages so templates can emit srcset. Source files must live under Root; remote URLs are rejected.
func (*Pipeline) FuncMap ¶ added in v0.1.1
FuncMap returns {{ img src attrs? }} for html/template.
{{ img "/hero.jpg" }}
{{ img "/hero.jpg" "Alt text" }}
{{ img "/hero.jpg" (dict "alt" "Hero" "width" 1440 "height" 810 "priority" true) }}
priority omits loading=lazy and sets fetchpriority=high (LCP / hero).
func (*Pipeline) Handler ¶ added in v0.1.1
func (p *Pipeline) Handler() (gin.HandlerFunc, error)
Handler returns the on-demand optimizer. Query: src=/file.jpg&w=375