converter

package
v0.0.0-...-f0620f4 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CategoryErrorDiffusion = "Error Diffusion"
	CategoryOrdered        = "Ordered"
	CategoryOther          = "Other"
)

Algorithm categories

View Source
const (
	// MaxWidth is the maximum width for Particle images
	MaxWidth = 400
	// MaxHeight is the maximum height for Particle images
	MaxHeight = 260
)

Variables

This section is empty.

Functions

func AdjustBrightness

func AdjustBrightness(img image.Image, brightness float32) image.Image

AdjustBrightness adjusts the brightness of an image. brightness ranges from -100 (completely dark) to +100 (completely bright). A value of 0 leaves the image unchanged.

func AdjustContrast

func AdjustContrast(img image.Image, contrast float32) image.Image

AdjustContrast adjusts the contrast of an image. contrast ranges from -100 (no contrast, gray) to +100 (maximum contrast). A value of 0 leaves the image unchanged.

func AlgorithmNames

func AlgorithmNames() []string

AlgorithmNames returns a sorted list of all algorithm names.

func ApplyDither

func ApplyDither(img image.Image, cfg DitherConfig) (image.Image, error)

ApplyDither applies dithering to an image using the specified configuration.

func FillAndCrop

func FillAndCrop(img image.Image, targetW, targetH int, anchor CropAnchor, offsetX, offsetY int) image.Image

FillAndCrop scales the image to fill the target dimensions, then crops excess. The anchor determines which part of the image is kept. offsetX and offsetY allow fine-tuning the crop position (positive = right/down).

func FitWithinBounds

func FitWithinBounds(img image.Image, maxW, maxH int) image.Image

FitWithinBounds resizes an image to fit within the specified bounds while maintaining aspect ratio. Only downscales - never upscales.

func GenerateOutputPath

func GenerateOutputPath(inputPath string) string

GenerateOutputPath creates a default output path from the input path.

func IsValidAlgorithm

func IsValidAlgorithm(name string) bool

IsValidAlgorithm checks if the given algorithm name is valid.

func ListAlgorithms

func ListAlgorithms() string

ListAlgorithms returns a formatted string listing all available algorithms.

func LoadImage

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

LoadImage loads an image from the given path. Supports PNG, JPEG, GIF, BMP, and WebP formats.

func ResizeToMax

func ResizeToMax(img image.Image) image.Image

ResizeToMax resizes an image to fit within the default max dimensions (400x260).

func ResizeWithConfig

func ResizeWithConfig(img image.Image, cfg ResizeConfig) image.Image

ResizeWithConfig resizes an image according to the given configuration.

Types

type AdjustConfig

type AdjustConfig struct {
	Brightness float32 // -100 to +100, 0 = no change
	Contrast   float32 // -100 to +100, 0 = no change
}

AdjustConfig holds image adjustment options.

type AlgorithmInfo

type AlgorithmInfo struct {
	Name        string
	Category    string
	Description string
}

AlgorithmInfo contains metadata about a dithering algorithm.

func SupportedAlgorithms

func SupportedAlgorithms() []AlgorithmInfo

SupportedAlgorithms returns information about all supported dithering algorithms.

type CropAnchor

type CropAnchor string

CropAnchor determines where cropping occurs when using fill mode.

const (
	CropAnchorCenter CropAnchor = "center"
	CropAnchorTop    CropAnchor = "top"
	CropAnchorBottom CropAnchor = "bottom"
	CropAnchorLeft   CropAnchor = "left"
	CropAnchorRight  CropAnchor = "right"
)

type DitherConfig

type DitherConfig struct {
	Algorithm  string
	Strength   float32 // 0.0 to 1.0
	Threshold  float32 // 0.0 to 1.0, for threshold dithering
	Serpentine bool
	BayerSize  int // 2, 4, 8, or 16
}

DitherConfig holds configuration for dithering operations.

func DefaultConfig

func DefaultConfig() DitherConfig

DefaultConfig returns the default dithering configuration.

type ImageOptions

type ImageOptions struct {
	Dither DitherConfig
	Resize ResizeConfig
	Adjust AdjustConfig
}

ImageOptions holds options for converting an image.Image directly.

type Options

type Options struct {
	InputPath   string
	OutputPath  string
	PreviewPath string
	Dither      DitherConfig
	Resize      ResizeConfig
	Adjust      AdjustConfig
	Preview     bool
}

Options holds all conversion options for file-based conversion.

type ReelConfig

type ReelConfig struct {
	Dither       DitherConfig
	Adjust       AdjustConfig
	MaxFrames    int // 0 = no limit (up to 90)
	SkipFrames   int // Take every Nth frame (1 = all frames)
	TargetFPS    int // 0 = use GIF timing
	TargetWidth  int // 0 = auto (max 200)
	TargetHeight int // 0 = auto (max 120)
}

ReelConfig holds configuration for reel conversion.

type ReelResult

type ReelResult struct {
	Reel           *preel.Reel
	DitheredFrames []image.Image
	InputWidth     int
	InputHeight    int
	OutputWidth    int
	OutputHeight   int
	InputFrames    int
	OutputFrames   int
}

ReelResult contains the reel conversion results.

func ConvertFramesToReel

func ConvertFramesToReel(frames []image.Image, delays []int, cfg ReelConfig) (*ReelResult, error)

ConvertFramesToReel converts a slice of images to a Particle reel.

func ConvertGIFToReel

func ConvertGIFToReel(gifPath string, cfg ReelConfig) (*ReelResult, error)

ConvertGIFToReel converts an animated GIF to a Particle reel.

func (*ReelResult) JSON

func (r *ReelResult) JSON() ([]byte, error)

JSON returns the reel as JSON bytes.

func (*ReelResult) JSONIndented

func (r *ReelResult) JSONIndented() ([]byte, error)

JSONIndented returns the reel as indented JSON bytes.

func (*ReelResult) String

func (r *ReelResult) String() (string, error)

String returns the reel as a JSON string.

type ResizeConfig

type ResizeConfig struct {
	Mode         ResizeMode
	Anchor       CropAnchor
	TargetWidth  int // 0 means use MaxWidth
	TargetHeight int // 0 means use MaxHeight
	OffsetX      int // Additional horizontal offset for crop (positive = right, negative = left)
	OffsetY      int // Additional vertical offset for crop (positive = down, negative = up)
}

ResizeConfig holds configuration for image resizing.

type ResizeMode

type ResizeMode string

ResizeMode determines how images are resized to fit target dimensions.

const (
	// ResizeModeFit scales the image to fit within bounds, maintaining aspect ratio.
	ResizeModeFit ResizeMode = "fit"
	// ResizeModeFill scales the image to fill bounds, cropping excess.
	ResizeModeFill ResizeMode = "fill"
)

type Result

type Result struct {
	ParticleImage *pimg.ParticleImage
	DitheredImage image.Image
	InputWidth    int
	InputHeight   int
	OutputWidth   int
	OutputHeight  int
}

Result contains the conversion results.

func Convert

func Convert(opts Options) (*Result, error)

Convert performs the full image conversion pipeline with file I/O. For library usage without file operations, use ConvertImage instead.

func ConvertImage

func ConvertImage(img image.Image, opts ImageOptions) (*Result, error)

ConvertImage converts an image.Image to Particle format without file I/O. This is the core conversion function for library usage.

func (*Result) JSON

func (r *Result) JSON() ([]byte, error)

JSON returns the particle image as JSON bytes.

func (*Result) JSONIndented

func (r *Result) JSONIndented() ([]byte, error)

JSONIndented returns the particle image as indented JSON bytes.

func (*Result) String

func (r *Result) String() (string, error)

String returns the particle image as a JSON string.

func (*Result) WriteToFile

func (r *Result) WriteToFile(path string) error

WriteToFile writes the result to a file.

Jump to

Keyboard shortcuts

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