Documentation
¶
Overview ¶
Package imageprep prepares untrusted images for display and storage.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Mode ¶
type Mode int
Mode chooses how the decoded image is resized. Fit preserves the aspect ratio without enlargement. Square crops the centre and resizes, including enlargement.
type Options ¶
type Options struct {
MaxBytes int64
MaxPixels int64
Size int
Mode Mode
Format Format
JPEGQuality int
}
Options sets input budgets, output dimensions, and encoding. MaxBytes, MaxPixels, and Size must be positive. Size is the maximum side for Fit and the exact side for Square. JPEGQuality must be 1–100 for JPEG output. MaxPixels also bounds the output bitmap. No input or output limits are implicit.
type Result ¶
Result holds the encoded image and its dimensions after orientation and resizing. MetadataError reports unreadable EXIF: preparation succeeds with the decoded orientation in that case. Callers decide how to report this partial result.
func Prepare ¶
Prepare decodes JPEG, PNG, GIF, or WebP, corrects EXIF orientation, resizes, and encodes an image. GIF inputs use their first frame; animated WebP is not supported. Metadata is not copied to the output. PNG preserves transparency; JPEG composites it on black. Input bytes and declared pixels are checked before full decoding, regardless of other image decoders registered by the calling program.