lilliput: github.com/discordapp/lilliput Index | Files | Directories

package lilliput

import "github.com/discordapp/lilliput"

Package lilliput resizes and encodes images from compressed images

Index

Package Files

avcodec.go giflib.go lilliput.go opencv.go ops.go

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")
)
var (
    ErrGifEncoderNeedsDecoder = errors.New("GIF encoder needs decoder used to create image")
)

func SetGIFMaxFrameDimension Uses

func SetGIFMaxFrameDimension(dim uint64)

SetGIFMaxFrameDimension sets the largest GIF width/height that can be decoded

type Decoder Uses

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
}

A Decoder decompresses compressed image data.

func NewDecoder Uses

func NewDecoder(buf []byte) (Decoder, error)

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 Uses

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 Uses

func NewEncoder(ext string, decodedBy Decoder, dst []byte) (Encoder, error)

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 Uses

type Framebuffer struct {
    // contains filtered or unexported fields
}

Framebuffer contains an array of raw, decoded pixel data.

func NewFramebuffer Uses

func NewFramebuffer(width, height int) *Framebuffer

NewFramebuffer creates the backing store for a pixel frame buffer.

func (*Framebuffer) Clear Uses

func (f *Framebuffer) Clear()

Clear resets all of the pixel data in Framebuffer.

func (*Framebuffer) Close Uses

func (f *Framebuffer) Close()

Close releases the resources associated with Framebuffer.

func (*Framebuffer) Fit Uses

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 Uses

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 Uses

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 Uses

func (f *Framebuffer) PixelType() PixelType

PixelType returns the PixelType information of the contained pixel data, if any.

func (*Framebuffer) ResizeTo Uses

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 Uses

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 Uses

type ImageHeader struct {
    // contains filtered or unexported fields
}

ImageHeader contains basic decoded image metadata.

func (*ImageHeader) Height Uses

func (h *ImageHeader) Height() int

Height returns the height of the image in number of pixels.

func (*ImageHeader) Orientation Uses

func (h *ImageHeader) Orientation() ImageOrientation

ImageOrientation returns the metadata-based image orientation.

func (*ImageHeader) PixelType Uses

func (h *ImageHeader) PixelType() PixelType

PixelType returns a PixelType describing the image's pixels.

func (*ImageHeader) Width Uses

func (h *ImageHeader) Width() int

Width returns the width of the image in number of pixels.

type ImageOps Uses

type ImageOps struct {
    // contains filtered or unexported fields
}

ImageOps is a reusable object that can resize and encode images.

func NewImageOps Uses

func NewImageOps(maxSize int) *ImageOps

NewImageOps creates a new ImageOps object that will operate on images up to maxSize on each axis.

func (*ImageOps) Clear Uses

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 Uses

func (o *ImageOps) Close()

Close releases resources associated with ImageOps

func (*ImageOps) Transform Uses

func (o *ImageOps) Transform(d Decoder, opt *ImageOptions, dst []byte) ([]byte, error)

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 Uses

type ImageOpsSizeMethod int
const (
    ImageOpsNoResize ImageOpsSizeMethod = iota
    ImageOpsFit
    ImageOpsResize
)

type ImageOptions Uses

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
}

ImageOptions controls how ImageOps resizes and encodes the pixel data decoded from a Decoder

type ImageOrientation Uses

type ImageOrientation int

ImageOrientation describes how the decoded image is oriented according to its metadata.

type PixelType Uses

type PixelType int

PixelType describes the base pixel type of the image.

func (PixelType) Channels Uses

func (p PixelType) Channels() int

Channels returns the number of channels in the PixelType.

func (PixelType) Depth Uses

func (p PixelType) Depth() int

Depth returns the number of bits in the PixelType.

Directories

PathSynopsis
examples

Package lilliput imports 8 packages (graph) and is imported by 3 packages. Updated 2019-02-18. Refresh now. Tools for package owners.