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 ¶
- Variables
- func AddImageHandler(f Handler, types ...string)
- func Fit(im Image, w, h uint) error
- func Pipeline(im Image, filters ...ImageFilter) error
- type Handler
- type Image
- type ImageCompression
- type ImageFilter
- type NativeImage
- func (im *NativeImage) Clean() error
- func (im *NativeImage) Close() error
- func (im *NativeImage) ContentType() string
- func (im *NativeImage) Encode(w io.Writer) error
- func (im *NativeImage) Format() string
- func (im *NativeImage) Gray16() error
- func (im *NativeImage) Grayscale() error
- 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) 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 ¶
var Gray16Palette = []color.Color{ color.RGBA{0x00, 0x00, 0x00, 0xff}, color.RGBA{0x11, 0x11, 0x11, 0xff}, color.RGBA{0x22, 0x22, 0x22, 0xff}, color.RGBA{0x33, 0x33, 0x33, 0xff}, color.RGBA{0x44, 0x44, 0x44, 0xff}, color.RGBA{0x55, 0x55, 0x55, 0xff}, color.RGBA{0x66, 0x66, 0x66, 0xff}, color.RGBA{0x77, 0x77, 0x77, 0xff}, color.RGBA{0x88, 0x88, 0x88, 0xff}, color.RGBA{0x99, 0x99, 0x99, 0xff}, color.RGBA{0xaa, 0xaa, 0xaa, 0xff}, color.RGBA{0xbb, 0xbb, 0xbb, 0xff}, color.RGBA{0xcc, 0xcc, 0xcc, 0xff}, color.RGBA{0xdd, 0xdd, 0xdd, 0xff}, color.RGBA{0xee, 0xee, 0xee, 0xff}, color.RGBA{0xff, 0xff, 0xff, 0xff}, }
Gray16Palette is a 16 level b&w palette.
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 Image ¶
type Image interface { Close() error Format() string ContentType() string Width() uint Height() uint SetFormat(string) error Resize(uint, uint) error Encode(io.Writer) error SetCompression(ImageCompression) error SetQuality(uint8) error Grayscale() error Gray16() 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 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) error
Encode encodes the image to an io.Writer.
func (*NativeImage) Format ¶
func (im *NativeImage) Format() string
Format returns the image format.
func (*NativeImage) Gray16 ¶
func (im *NativeImage) Gray16() error
Gray16 transforms the image to a 16 gray levels palette, applying a Floyd Steinberg dithering. It is better to convert the image to grayscale before this operation.
func (*NativeImage) Grayscale ¶
func (im *NativeImage) Grayscale() error
Grayscale transforms the image to a grayscale version.
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.