Documentation
¶
Overview ¶
Package img provides a unified image loader and manipulation pipeline. It can load images using the native go implementations for the major web image types, perform some manipulation like resizing and write the result to an io.Writer.
Index ¶
- func AddImageHandler(f Handler, types ...string)
- func Fit(im Image, w, h uint) error
- func Pipeline(im Image, filters ...ImageFilter) error
- type GIFImage
- func (im *GIFImage) Clean() error
- func (im *GIFImage) Close() error
- func (im *GIFImage) ContentType() string
- func (im *GIFImage) Encode(w io.Writer) (string, error)
- func (im *GIFImage) FirstFrame() Image
- func (im *GIFImage) Format() string
- func (im *GIFImage) Frames() uint
- func (im *GIFImage) Height() uint
- func (im *GIFImage) Resize(w, h uint) error
- func (im *GIFImage) SetCompression(c ImageCompression) error
- func (im *GIFImage) SetFormat(_ string) error
- func (im *GIFImage) SetQuality(_ uint8) error
- func (im *GIFImage) Width() uint
- type Handler
- type Image
- type ImageCompression
- type ImageFilter
- type MultiFrameImage
- type NativeImage
- func (im *NativeImage) Clean() error
- func (im *NativeImage) Close() error
- func (im *NativeImage) ContentType() string
- func (im *NativeImage) Encode(w io.Writer) (string, error)
- func (im *NativeImage) Format() string
- func (im *NativeImage) Height() uint
- func (im *NativeImage) Image() image.Image
- func (im *NativeImage) Resize(w, h uint) error
- func (im *NativeImage) SetCompression(c ImageCompression) error
- func (im *NativeImage) SetFormat(f string) error
- func (im *NativeImage) SetQuality(q uint8) error
- func (im *NativeImage) Width() uint
- type SvgImage
- func (im *SvgImage) Clean() error
- func (im *SvgImage) Close() error
- func (im *SvgImage) ContentType() string
- func (im *SvgImage) Encode(w io.Writer) (string, error)
- func (im *SvgImage) Format() string
- func (im *SvgImage) Gray16() error
- func (im *SvgImage) Grayscale() error
- func (im *SvgImage) Height() uint
- func (im *SvgImage) Resize(w, h uint) error
- func (im *SvgImage) SetCompression(ImageCompression) error
- func (im *SvgImage) SetFormat(string) error
- func (im *SvgImage) SetQuality(uint8) error
- func (im *SvgImage) Width() uint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddImageHandler ¶
AddImageHandler adds (or replaces) a handler for the given types.
func Fit ¶
Fit resizes the image keeping the aspect ratio and staying within the given width and height.
func Pipeline ¶
func Pipeline(im Image, filters ...ImageFilter) error
Pipeline apply all the given ImageFilter functions to the image.
Types ¶
type GIFImage ¶
GIFImage is the Image implementation for GIF files only.
func NewGIFImage ¶
NewGIFImage returns a GIFImage instance that decodes all frames from a GIF image.
func (*GIFImage) Close ¶
Close frees the resources used by the image and must be called when you're done processing it.
func (*GIFImage) ContentType ¶
ContentType returns the image mimetype.
func (*GIFImage) FirstFrame ¶
FirstFrame returns the first GIF's image as an Image.
func (*GIFImage) SetCompression ¶
func (im *GIFImage) SetCompression(c ImageCompression) error
SetCompression sets the compression level of PNG endoding.
func (*GIFImage) SetQuality ¶
SetQuality is a noop function for this image family.
type Image ¶
type Image interface {
Close() error
Format() string
ContentType() string
Width() uint
Height() uint
SetFormat(string) error
Resize(uint, uint) error
Encode(io.Writer) (string, error)
SetCompression(ImageCompression) error
SetQuality(uint8) error
Clean() error
}
Image describes the interface of an image manipulation type.
type ImageCompression ¶
type ImageCompression uint8
ImageCompression is the compression level used for PNG images.
const ( // CompressionFast is a fast method. CompressionFast ImageCompression = iota // CompressionBest is the best space saving method. CompressionBest )
type ImageFilter ¶
ImageFilter is a filter application function used by the Pipeline method of an Image instance.
type MultiFrameImage ¶
MultiFrameImage describes the interface of an image with multiple frames, such as animated GIFs.
type NativeImage ¶
type NativeImage struct {
// contains filtered or unexported fields
}
NativeImage is the Image implementation using Go native image tools.
func NewNativeImage ¶
func NewNativeImage(r io.Reader) (*NativeImage, error)
NewNativeImage returns a NativeImage instance using Go native image tools.
func (*NativeImage) Clean ¶
func (im *NativeImage) Clean() error
Clean is a noop function for this image family.
func (*NativeImage) Close ¶
func (im *NativeImage) Close() error
Close frees the resources used by the image and must be called when you're done processing it.
func (*NativeImage) ContentType ¶
func (im *NativeImage) ContentType() string
ContentType returns the image mimetype.
func (*NativeImage) Encode ¶
func (im *NativeImage) Encode(w io.Writer) (string, error)
Encode encodes the image to an io.Writer.
func (*NativeImage) Format ¶
func (im *NativeImage) Format() string
Format returns the image format.
func (*NativeImage) Image ¶
func (im *NativeImage) Image() image.Image
Image returns the wrapped image instance.
func (*NativeImage) Resize ¶
func (im *NativeImage) Resize(w, h uint) error
Resize resizes the image to the given width and height.
func (*NativeImage) SetCompression ¶
func (im *NativeImage) SetCompression(c ImageCompression) error
SetCompression sets the compression level of PNG encoding.
func (*NativeImage) SetFormat ¶
func (im *NativeImage) SetFormat(f string) error
SetFormat sets the encoding format. When none is set, it will use the original format or fallback to JPEG.
func (*NativeImage) SetQuality ¶
func (im *NativeImage) SetQuality(q uint8) error
SetQuality sets the quality of JEPG encoding.
type SvgImage ¶
type SvgImage struct {
// contains filtered or unexported fields
}
SvgImage is the Image implementation for SVG images.
func NewSvgImage ¶
NewSvgImage returns an SvgImage instance.
func (*SvgImage) Clean ¶
Clean sanitizes the SVG image by keeping only a specific set of tags and attributes.
func (*SvgImage) ContentType ¶
ContentType returns the image mimetype.
func (*SvgImage) SetCompression ¶
func (im *SvgImage) SetCompression(ImageCompression) error
SetCompression is a noop here.
func (*SvgImage) SetQuality ¶
SetQuality is a noop here.