Documentation ¶
Overview ¶
Package lilliput resizes and encodes images from compressed images
Index ¶
- Constants
- Variables
- func SetGIFMaxFrameDimension(dim uint64)
- type Decoder
- type Encoder
- type Framebuffer
- func (f *Framebuffer) Clear()
- func (f *Framebuffer) Close()
- func (f *Framebuffer) Duration() time.Duration
- func (f *Framebuffer) Fit(width, height int, dst *Framebuffer) error
- func (f *Framebuffer) Height() int
- func (f *Framebuffer) OrientationTransform(orientation ImageOrientation)
- func (f *Framebuffer) PixelType() PixelType
- func (f *Framebuffer) ResizeTo(width, height int, dst *Framebuffer) error
- func (f *Framebuffer) Width() int
- type ImageHeader
- type ImageOps
- type ImageOpsSizeMethod
- type ImageOptions
- type ImageOrientation
- type PixelType
Constants ¶
const ( JpegQuality = int(C.CV_IMWRITE_JPEG_QUALITY) PngCompression = int(C.CV_IMWRITE_PNG_COMPRESSION) WebpQuality = int(C.CV_IMWRITE_WEBP_QUALITY) JpegProgressive = int(C.CV_IMWRITE_JPEG_PROGRESSIVE) OrientationTopLeft = ImageOrientation(C.CV_IMAGE_ORIENTATION_TL) OrientationTopRight = ImageOrientation(C.CV_IMAGE_ORIENTATION_TR) OrientationBottomRight = ImageOrientation(C.CV_IMAGE_ORIENTATION_BR) OrientationBottomLeft = ImageOrientation(C.CV_IMAGE_ORIENTATION_BL) OrientationLeftTop = ImageOrientation(C.CV_IMAGE_ORIENTATION_LT) OrientationRightTop = ImageOrientation(C.CV_IMAGE_ORIENTATION_RT) OrientationRightBottom = ImageOrientation(C.CV_IMAGE_ORIENTATION_RB) OrientationLeftBottom = ImageOrientation(C.CV_IMAGE_ORIENTATION_LB) )
Variables ¶
var ( ErrInvalidImage = errors.New("unrecognized image format") ErrDecodingFailed = errors.New("failed to decode image") ErrBufTooSmall = errors.New("buffer too small to hold image") ErrFrameBufNoPixels = errors.New("Framebuffer contains no pixels") ErrSkipNotSupported = errors.New("skip operation not supported by this decoder") )
var (
ErrGifEncoderNeedsDecoder = errors.New("GIF encoder needs decoder used to create image")
)
Functions ¶
func SetGIFMaxFrameDimension ¶
func SetGIFMaxFrameDimension(dim uint64)
SetGIFMaxFrameDimension sets the largest GIF width/height that can be decoded
Types ¶
type Decoder ¶
type Decoder interface { // Header returns basic image metadata from the image. // This is done lazily, reading only the first part of the image and not // a full decode. Header() (*ImageHeader, error) // Close releases any resources associated with the Decoder Close() // Description returns a string description of the image type, such as // "PNG" Description() string // Duration returns the duration of the content. This property is 0 for // static images and animated GIFs. Duration() time.Duration // DecodeTo fully decodes the image pixel data into f. Generally users should // prefer instead using the ImageOps object to decode images. DecodeTo(f *Framebuffer) error // SkipFrame skips a frame if the decoder supports multiple frames // and returns io.EOF if the last frame has been reached SkipFrame() error }
A Decoder decompresses compressed image data.
func NewDecoder ¶
NewDecoder returns a Decoder which can be used to decode image data provided in buf. If the first few bytes of buf do not point to a valid magic string, an error will be returned.
type Encoder ¶
type Encoder interface { // Encode encodes the pixel data in f into the dst provided to NewEncoder. Encode quality // options can be passed into opt, such as map[int]int{lilliput.JpegQuality: 80} Encode(f *Framebuffer, opt map[int]int) ([]byte, error) // Close releases any resources associated with the Encoder Close() }
An Encoder compresses raw pixel data into a well-known image type.
func NewEncoder ¶
NewEncoder returns an Encode which can be used to encode Framebuffer into compressed image data. ext should be a string like ".jpeg" or ".png". decodedBy is optional and can be the Decoder used to make the Framebuffer. dst is where an encoded image will be written.
type Framebuffer ¶
type Framebuffer struct {
// contains filtered or unexported fields
}
Framebuffer contains an array of raw, decoded pixel data.
func NewFramebuffer ¶
func NewFramebuffer(width, height int) *Framebuffer
NewFramebuffer creates the backing store for a pixel frame buffer.
func (*Framebuffer) Clear ¶
func (f *Framebuffer) Clear()
Clear resets all of the pixel data in Framebuffer.
func (*Framebuffer) Close ¶
func (f *Framebuffer) Close()
Close releases the resources associated with Framebuffer.
func (*Framebuffer) Duration ¶
func (f *Framebuffer) Duration() time.Duration
Duration returns the length of time this frame plays out in an animated image
func (*Framebuffer) Fit ¶
func (f *Framebuffer) Fit(width, height int, dst *Framebuffer) error
Fit performs a resizing and cropping transform on the Framebuffer and puts the result in the provided destination Framebuffer. This function does preserve aspect ratio but will crop columns or rows from the edges of the image as necessary in order to keep from stretching the image content. Returns an error if the destination is not large enough to hold the given dimensions.
func (*Framebuffer) Height ¶
func (f *Framebuffer) Height() int
Height returns the height of the contained pixel data in number of pixels. This may differ from the capacity of the framebuffer.
func (*Framebuffer) OrientationTransform ¶
func (f *Framebuffer) OrientationTransform(orientation ImageOrientation)
OrientationTransform rotates and/or mirrors the Framebuffer. Passing the orientation given by the ImageHeader will normalize the orientation of the Framebuffer.
func (*Framebuffer) PixelType ¶
func (f *Framebuffer) PixelType() PixelType
PixelType returns the PixelType information of the contained pixel data, if any.
func (*Framebuffer) ResizeTo ¶
func (f *Framebuffer) ResizeTo(width, height int, dst *Framebuffer) error
ResizeTo performs a resizing transform on the Framebuffer and puts the result in the provided destination Framebuffer. This function does not preserve aspect ratio if the given dimensions differ in ratio from the source. Returns an error if the destination is not large enough to hold the given dimensions.
func (*Framebuffer) Width ¶
func (f *Framebuffer) Width() int
Width returns the width of the contained pixel data in number of pixels. This may differ from the capacity of the framebuffer.
type ImageHeader ¶
type ImageHeader struct {
// contains filtered or unexported fields
}
ImageHeader contains basic decoded image metadata.
func (*ImageHeader) Height ¶
func (h *ImageHeader) Height() int
Height returns the height of the image in number of pixels.
func (*ImageHeader) IsAnimated ¶
func (h *ImageHeader) IsAnimated() bool
func (*ImageHeader) Orientation ¶
func (h *ImageHeader) Orientation() ImageOrientation
ImageOrientation returns the metadata-based image orientation.
func (*ImageHeader) PixelType ¶
func (h *ImageHeader) PixelType() PixelType
PixelType returns a PixelType describing the image's pixels.
func (*ImageHeader) Width ¶
func (h *ImageHeader) Width() int
Width returns the width of the image in number of pixels.
type ImageOps ¶
type ImageOps struct {
// contains filtered or unexported fields
}
ImageOps is a reusable object that can resize and encode images.
func NewImageOps ¶
NewImageOps creates a new ImageOps object that will operate on images up to maxSize on each axis.
func (*ImageOps) Clear ¶
func (o *ImageOps) Clear()
Clear resets all pixel data in ImageOps. This need not be called between calls to Transform. You may choose to call this to remove image data from memory.
func (*ImageOps) Close ¶
func (o *ImageOps) Close()
Close releases resources associated with ImageOps
func (*ImageOps) Transform ¶
Transform performs the requested transform operations on the Decoder specified by d. The result is written into the output buffer dst. A new slice pointing to dst is returned with its length set to the length of the resulting image. Errors may occur if the decoded image is too large for ImageOps or if Encoding fails.
It is important that .Decode() not have been called already on d.
type ImageOpsSizeMethod ¶
type ImageOpsSizeMethod int
const ( ImageOpsNoResize ImageOpsSizeMethod = iota ImageOpsFit ImageOpsResize )
type ImageOptions ¶
type ImageOptions struct { // FileType should be a string starting with '.', e.g. // ".jpeg" FileType string // Width controls the width of the output image Width int // Height controls the height of the output image Height int // ResizeMethod controls how the image will be transformed to // its output size. Notably, ImageOpsFit will do a cropping // resize, while ImageOpsResize will stretch the image. ResizeMethod ImageOpsSizeMethod // NormalizeOrientation will flip and rotate the image as necessary // in order to undo EXIF-based orientation NormalizeOrientation bool // EncodeOptions controls the encode quality options EncodeOptions map[int]int // MaxEncodeFrames controls the maximum number of frames that will be resized MaxEncodeFrames int // MaxEncodeDuration controls the maximum duration of animated image that will be resized MaxEncodeDuration time.Duration }
ImageOptions controls how ImageOps resizes and encodes the pixel data decoded from a Decoder
type ImageOrientation ¶
type ImageOrientation int
ImageOrientation describes how the decoded image is oriented according to its metadata.