Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownFormat is returned when trying to encode an image whose format // is not registered in an Encoder. ErrUnknownFormat = errors.New("unknown format") )
Functions ¶
func GIFEncoder ¶
GIFEncoder encodes images using gif.Encode with default options.
func JPEGEncoder ¶
JPEGEncoder encodes images using jpeg.Encode with maximum quality.
Types ¶
type Dimensions ¶
Dimensions are image dimensions (width & height).
type Encoder ¶
type Encoder interface { // Encode encodes an image using the appropriate FormatEncoder for the // specified format. Encode(io.Writer, image.Image, string) error }
Encoder is a multi-format image encoder.
func NewEncoder ¶
func NewEncoder(opts ...EncoderOption) Encoder
NewEncoder returns a new Encoder with default support for JPEGs, GIFs and PNGs. When provided an unknown image format, Encoder falls back to the PNG encoder.
type EncoderOption ¶
type EncoderOption func(*encoder)
EncoderOption is an Encoder option.
func WithFormat ¶
func WithFormat(format string, enc FormatEncoder) EncoderOption
WithFormat returns an EncoderOption that registers a FormatEncoder for the given image format.
Format must be the same as would be returned by image.Decode. Provide an empty string as format to set the default encoder for unknown formats.
type FormatEncoder ¶
type FormatEncoder interface { // Encode encodes the provided Image and writes the result into the // specified Writer. Encode(io.Writer, image.Image) error }
FormatEncoder encodes images of a specific format (JPEG, PNG etc.).
type PNGCompressor ¶
type PNGCompressor png.CompressionLevel
PNGCompressor compresses images using a png.Encoder.
var img image.Image c := PNGCompressor(png.BestCompression) compressed := c.Compress(img)
func (PNGCompressor) Compress ¶
Compress compresses the provided Image and returns the compressed Image. Compressor uses a png.Encoder to compress the Image with comp.CompressionLevel() as the compression level.
func (PNGCompressor) CompressionLevel ¶
func (comp PNGCompressor) CompressionLevel() png.CompressionLevel
CompressionLevel returns the png.CompressionLevel.
type Resizer ¶
type Resizer map[string]Dimensions
A Resizer resizes images into different Dimensions. Resizing is done in parallel for each Dimensions.
func (*Resizer) Resize ¶
Resize resizes an Image into the configured Dimensions. Providing 0 as the Width or Height for Dimensions of a size preserves the aspect-ratio for that size.
var img image.Image r := Resizer{ "small": {Width: 640, Height: 0}, "medium": {Width: 1280, Height: 0}, "large": {Width: 1920, Height: 0}, } resized := r.Resize(img) // resized["small"].Bounds().Dx() == 640 // resized["medium"].Bounds().Dx() == 1280 // resized["large"].Bounds().Dx() == 1920
Directories ¶
Path | Synopsis |
---|---|
mock_gallery
Package mock_gallery is a generated GoMock package.
|
Package mock_gallery is a generated GoMock package. |
Package mock_image is a generated GoMock package.
|
Package mock_image is a generated GoMock package. |