Documentation
¶
Overview ¶
Package imageopt turns arbitrary uploaded photos into small, good-looking WebP files. It is shared by the upload handlers (api) and the one-off backfill command (cmd/optimize_images) so both produce identical output.
Index ¶
Constants ¶
const ( // MaxDim caps the long edge. 1920px keeps small print on a receipt // legible while shrinking a 12MP phone photo to a fraction of its size. MaxDim = 1920 // Quality is libwebp's lossy 0-100 scale; ~75 is the "good, not // pristine" knee -- visually close to the source at roughly a quarter of // the JPEG bytes. Quality = 75 ContentType = "image/webp" Ext = ".webp" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Result ¶
type Result struct {
Data []byte
ContentType string
Ext string
// Optimized is false when the original bytes were kept unchanged.
Optimized bool
}
Result is what a caller persists: the bytes to write and the metadata that must describe *those* bytes (not the original upload).
func Optimize ¶
Optimize decodes the photo (honouring EXIF orientation, which a re-encode would otherwise drop and leave phone photos sideways), downsizes it to MaxDim, and re-encodes it as lossy WebP.
It never makes an image worse: if the result isn't smaller than the original, or the format can't be decoded here (e.g. HEIC), the original bytes come back unchanged under their declared type.