recoder

package module
v0.0.0-...-8836395 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: MIT Imports: 8 Imported by: 0

README

Recoder

Basic module to help with removing disposal from GIFs

Usage

Recoder can be invoked with RecodeImage(io.Reader, QuantizationAttributes) or directly via CLI, however, CLI is only intended to demonstrate what it can do.

The purpose of recoder is to handle iterating between frames with certain libraries which do not not handle disposal to automatically apply the previous frame beforehand. It is then expected that output file sizes to be a bit larger than the source image.

Usage of recoder:
  -In string
        Input filename
  -Out string
        Output filename
  -Speed int
        Speed (1 slowest, 10 fastest) (default 3)```

Quantization Attributes

The current QuantizationAttributes are MaxColors, MinQuality, MaxQuality and Speed which are provided by ImageQuant. Default values can be retrieved with NewQuantizationAttributes().

Documentation

Index

Constants

View Source
const (
	ColorsMin = 2
	ColorsMax = 256

	QualityMin int = 0
	QualityMax int = 100

	SpeedSlowest int = 1
	SpeedDefault int = 3
	SpeedFastest int = 10
)
View Source
const VERSION = "1.0.0"

VERSION respects semantic versioning.

Variables

This section is empty.

Functions

func RecodeImage

func RecodeImage(r io.Reader, qa QuantizationAttributes) (dst io.Reader, err error)

RecodeImage handles GIF re-encoding.

Types

type QuantizationAttributes

type QuantizationAttributes struct {
	// Specifies maximum number of colors to use. The default is 256.
	// Instead of setting a fixed limit it's better to use MinQuality and MaxQuality
	MaxColors int
	// Quality is in range 0 (worst) to 100 (best) and values are analoguous to JPEG quality
	// (i.e. 80 is usually good enough). Quantization will attempt to use the lowest number
	// of colors needed to achieve maximum quality. maximum value of 100 is the default and
	// means conversion as good as possible. If it's not possible to convert the image with
	// at least minimum quality (i.e. 256 colors is not enough to meet the minimum quality),
	// then Image.Quantize() will fail. The default minimum is 0 (proceeds regardless of quality).
	//
	// Features dependent on speed:
	// speed 1-5: Noise-sensitive dithering
	// speed 8-10 or if image has more than million colors: Forced posterization
	// speed 1-7 or if minimum quality is set: Quantization error known
	// speed 1-6: Additional quantization techniques
	MinQuality int
	MaxQuality int
	// Higher speed levels disable expensive algorithms and reduce quantization precision. The
	// default speed is 3. Speed 1 gives marginally better quality at significant CPU cost.
	// Speed 10 has usually 5% lower quality, but is 8 times faster than the default. High
	// speeds combined with Quality will use more colors than necessary and will be less likely
	// to meet minimum required quality.
	Speed int
}

QuantizationAttributes represents all attributes provided to imagequant.

func NewQuantizationAttributes

func NewQuantizationAttributes() QuantizationAttributes

NewQuantizationAttributes returns the default quantization attributes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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