image

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

SupportedFormats lists all supported image formats

Functions

func Convert

func Convert(src image.Image, opts ConvertOptions) (image.Image, error)

Convert converts an image to a different format The actual format conversion happens during Save()

func ConvertFile

func ConvertFile(inputPath string, opts ConvertOptions) (image.Image, error)

ConvertFile loads an image and prepares it for conversion

func Encode

func Encode(w io.Writer, img image.Image, opts SaveOptions) error

Encode writes an image to an io.Writer

func GenerateOutputPath

func GenerateOutputPath(inputPath string, format Format, suffix string) string

GenerateOutputPath creates an output path based on input and format

func IsSupported

func IsSupported(format Format) bool

IsSupported checks if a format is supported

func Load

func Load(path string) (image.Image, error)

Load reads an image from a file path

func LoadFromReader

func LoadFromReader(r io.Reader) (image.Image, error)

LoadFromReader reads an image from an io.Reader

func Resize

func Resize(src image.Image, opts ResizeOptions) (image.Image, error)

Resize resizes an image according to the specified options

func ResizeFile

func ResizeFile(inputPath string, opts ResizeOptions) (image.Image, error)

ResizeFile loads, resizes, and returns the processed image

func Save

func Save(img image.Image, path string, opts ...SaveOptions) error

Save writes an image to a file

Types

type ConvertOptions

type ConvertOptions struct {
	Format  Format // Target format
	Quality int    // Output quality (1-100, for JPEG)
}

ConvertOptions configures image conversion

type EXIFData

type EXIFData struct {
	Make         string     `json:"make,omitempty"`
	Model        string     `json:"model,omitempty"`
	DateTime     *time.Time `json:"datetime,omitempty"`
	Orientation  int        `json:"orientation,omitempty"`
	ExposureTime string     `json:"exposure_time,omitempty"`
	FNumber      string     `json:"f_number,omitempty"`
	ISOSpeed     int        `json:"iso_speed,omitempty"`
	FocalLength  string     `json:"focal_length,omitempty"`
	GPSLatitude  float64    `json:"gps_latitude,omitempty"`
	GPSLongitude float64    `json:"gps_longitude,omitempty"`
}

EXIFData contains EXIF metadata from photos

type Format

type Format string

Format represents a supported image format

const (
	FormatPNG  Format = "png"
	FormatJPEG Format = "jpeg"
	FormatJPG  Format = "jpg"
	FormatGIF  Format = "gif"
	FormatBMP  Format = "bmp"
	FormatTIFF Format = "tiff"
	FormatWEBP Format = "webp"
)

func FormatFromExtension

func FormatFromExtension(filename string) Format

FormatFromExtension extracts format from filename

func NormalizeFormat

func NormalizeFormat(format string) Format

NormalizeFormat normalizes format strings (e.g., "jpg" -> "jpeg")

type Metadata

type Metadata struct {
	Width     int       `json:"width"`
	Height    int       `json:"height"`
	Format    string    `json:"format"`
	SizeBytes int64     `json:"size_bytes"`
	ColorMode string    `json:"color_mode,omitempty"`
	HasAlpha  bool      `json:"has_alpha"`
	EXIF      *EXIFData `json:"exif,omitempty"`
}

Metadata contains image information

func Info

func Info(inputPath string) (*Metadata, error)

Info extracts metadata from an image file

type ResizeOptions

type ResizeOptions struct {
	Width   int    // Target width in pixels (0 to auto-calculate from aspect ratio)
	Height  int    // Target height in pixels (0 to auto-calculate from aspect ratio)
	Fit     string // Fit mode: "contain", "cover", "fill"
	Quality int    // Output quality (1-100, for JPEG/WebP)
}

ResizeOptions configures image resizing behavior

type SaveOptions

type SaveOptions struct {
	Format  Format // Target format (defaults to extension-based detection)
	Quality int    // Quality for lossy formats (1-100, default 85)
}

SaveOptions configures image saving

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL