Documentation
¶
Index ¶
- func CalculateReduction(original, compressed int64) float64
- func FormatBytes(bytes int64) string
- func GenerateOutputPath(inputPath string, options CompressionOptions) string
- type CompressionOptions
- type CompressionResult
- type Compressor
- type ImageFormat
- type ImageInfo
- type JPEGCompressor
- type PNGCompressor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateReduction ¶
CalculateReduction calculates the percentage reduction
func FormatBytes ¶
FormatBytes formats bytes into human-readable string
func GenerateOutputPath ¶
func GenerateOutputPath(inputPath string, options CompressionOptions) string
GenerateOutputPath creates the output path based on options
Types ¶
type CompressionOptions ¶
type CompressionOptions struct {
// Common options
Quality int // 1-100 for JPEG, ignored for PNG
ResizePercent float64 // 0-100, 0 means no resize
ResizeWidth int // Target width, 0 means auto
ResizeHeight int // Target height, 0 means auto
StripMetadata bool // Remove EXIF and other metadata
OutputDir string // Output directory, empty means same as input
OutputSuffix string // Suffix to add to filename (e.g., "_compressed")
// JPEG specific
Progressive bool // Progressive JPEG encoding
ChromaSubsample string // "4:4:4", "4:2:2", "4:2:0"
// PNG specific
CompressionLevel int // 0-9, higher = more compression
Interlaced bool // Adam7 interlacing
}
CompressionOptions holds all compression settings
func DefaultOptions ¶
func DefaultOptions() CompressionOptions
DefaultOptions returns sensible default compression options
type CompressionResult ¶
type CompressionResult struct {
InputPath string
OutputPath string
InputSize int64
OutputSize int64
Reduction float64 // Percentage reduction
Width int
Height int
Success bool
Error error
}
CompressionResult contains the result of a compression operation
type Compressor ¶
type Compressor interface {
Compress(inputPath string, options CompressionOptions) (*CompressionResult, error)
GetInfo(inputPath string) (*ImageInfo, error)
EstimateSize(inputPath string, options CompressionOptions) (int64, error)
}
Compressor interface defines the compression operations
type ImageFormat ¶
type ImageFormat string
ImageFormat represents supported image formats
const ( FormatJPEG ImageFormat = "jpeg" FormatPNG ImageFormat = "png" )
func GetImageFormat ¶
func GetImageFormat(path string) (ImageFormat, error)
GetImageFormat detects the image format from file extension
type ImageInfo ¶
type ImageInfo struct {
Path string
Format ImageFormat
Width int
Height int
Size int64
ColorMode string
}
ImageInfo contains information about an image
func GetImageInfo ¶
GetImageInfo returns information about an image file
type JPEGCompressor ¶
type JPEGCompressor struct{}
JPEGCompressor handles JPEG image compression
func NewJPEGCompressor ¶
func NewJPEGCompressor() *JPEGCompressor
NewJPEGCompressor creates a new JPEG compressor
func (*JPEGCompressor) Compress ¶
func (c *JPEGCompressor) Compress(inputPath string, options CompressionOptions) (*CompressionResult, error)
Compress compresses a JPEG image with the given options
func (*JPEGCompressor) EstimateSize ¶
func (c *JPEGCompressor) EstimateSize(inputPath string, options CompressionOptions) (int64, error)
EstimateSize estimates the compressed size based on options
type PNGCompressor ¶
type PNGCompressor struct{}
PNGCompressor handles PNG image compression
func NewPNGCompressor ¶
func NewPNGCompressor() *PNGCompressor
NewPNGCompressor creates a new PNG compressor
func (*PNGCompressor) Compress ¶
func (c *PNGCompressor) Compress(inputPath string, options CompressionOptions) (*CompressionResult, error)
Compress compresses a PNG image with the given options
func (*PNGCompressor) EstimateSize ¶
func (c *PNGCompressor) EstimateSize(inputPath string, options CompressionOptions) (int64, error)
EstimateSize estimates the compressed size based on options