Documentation
¶
Overview ¶
Package media provides utilities for processing media content (images, video).
Index ¶
Constants ¶
View Source
const ( FormatJPEG = "jpeg" FormatJPG = "jpg" FormatPNG = "png" FormatGIF = "gif" FormatWebP = "webp" )
Image format constants.
View Source
const ( MIMETypeJPEG = "image/jpeg" MIMETypePNG = "image/png" MIMETypeGIF = "image/gif" MIMETypeWebP = "image/webp" )
MIME type constants.
View Source
const ( DefaultMaxWidth = 1024 DefaultMaxHeight = 1024 DefaultQuality = 85 MinQuality = 10 QualityDecay = 0.9 )
Default configuration values.
Variables ¶
This section is empty.
Functions ¶
func MIMETypeToFormat ¶
MIMETypeToFormat converts a MIME type to format string.
Types ¶
type ImageResizeConfig ¶
type ImageResizeConfig struct {
// MaxWidth is the maximum width in pixels (0 = no limit).
MaxWidth int
// MaxHeight is the maximum height in pixels (0 = no limit).
MaxHeight int
// MaxSizeBytes is the maximum encoded size in bytes (0 = no limit).
// If exceeded after resize, quality is reduced iteratively.
MaxSizeBytes int64
// Quality is the encoding quality (1-100). Used for JPEG and WebP.
// Default: 85.
Quality int
// Format is the output format ("jpeg", "png", "" = preserve original).
Format string
// PreserveAspectRatio maintains the original aspect ratio when resizing.
// Default: true.
PreserveAspectRatio bool
// SkipIfSmaller skips processing if the image is already within limits.
// Default: true.
SkipIfSmaller bool
}
ImageResizeConfig configures image resizing behavior.
func DefaultImageResizeConfig ¶
func DefaultImageResizeConfig() ImageResizeConfig
DefaultImageResizeConfig returns sensible defaults for image resizing.
type ResizeResult ¶
type ResizeResult struct {
Data []byte
Format string
MIMEType string
Width int
Height int
OriginalSize int64
NewSize int64
WasResized bool
}
ResizeResult contains the result of an image resize operation.
func ResizeImage ¶
func ResizeImage(data []byte, config ImageResizeConfig) (*ResizeResult, error)
ResizeImage resizes an image to fit within the configured dimensions. Returns the resized image data, format, and any error.
Click to show internal directories.
Click to hide internal directories.