fotomat: github.com/die-net/fotomat/format Index | Files

package format

import "github.com/die-net/fotomat/format"

Index

Package Files

format.go metadata.go orientation.go save.go

Constants

const (
    // DefaultQuality is used when SaveOptions.Quality is unspecified.
    DefaultQuality = 85
    // DefaultCompression is used when SaveOptions.Compression is unspecified.
    DefaultCompression = 6
)

Variables

var (
    // ErrInvalidOperation is returned for an invalid operation on this image format.
    ErrInvalidOperation = errors.New("Invalid operation")
    // ErrUnknownFormat is returned when the given image is in an unknown format.
    ErrUnknownFormat = errors.New("Unknown image format")
)
var ErrInvalidSaveFormat = errors.New("Invalid save format")

ErrInvalidSaveFormat is returned if the specified Format can't be written to.

func Save Uses

func Save(image *vips.Image, options SaveOptions) ([]byte, error)

Save returns an Image compressed using the given SaveOptions as a byte slice.

type Format Uses

type Format int

Format of compressed image.

const (
    Unknown Format = iota
    Jpeg
    Png
    Gif
    Webp
)

Format of compressed image.

func DetectFormat Uses

func DetectFormat(blob []byte) Format

DetectFormat detects the Format of the supplied byte slice.

func (Format) CanLoadBytes Uses

func (format Format) CanLoadBytes() bool

CanLoadBytes returns true if we know how to load this format from a byte slice.

func (Format) CanLoadFile Uses

func (format Format) CanLoadFile() bool

CanLoadFile returns true if we know how to load this format from a file.

func (Format) LoadBytes Uses

func (format Format) LoadBytes(blob []byte) (*vips.Image, error)

LoadBytes loads byte slice in a given format and returns an Image.

func (Format) LoadFile Uses

func (format Format) LoadFile(filename string) (*vips.Image, error)

LoadFile loads a file in a given Format and returns an Image.

func (Format) MetadataBytes Uses

func (format Format) MetadataBytes(blob []byte) (Metadata, error)

MetadataBytes parses an image byte slice in known format and returns Metadata or an error.

func (Format) MetadataFile Uses

func (format Format) MetadataFile(filename string) (Metadata, error)

MetadataFile parses an image file in known format and returns Metadata or an error.

func (Format) String Uses

func (format Format) String() string

String returns the mime type of given image format.

type Metadata Uses

type Metadata struct {
    Width       int
    Height      int
    Format      Format
    Orientation Orientation
    HasAlpha    bool
}

Metadata is the currently-known metadata about an Image.

func MetadataBytes Uses

func MetadataBytes(blob []byte) (Metadata, error)

MetadataBytes parses an image byte slice and returns Metadata or an error.

func MetadataImage Uses

func MetadataImage(image *vips.Image) Metadata

MetadataImage returns Metadata from an Image. Format is always unset.

type Orientation Uses

type Orientation int

Orientation is the current Image orientation, as stored by a camera.

const (
    Undefined Orientation = iota
    TopLeft
    TopRight
    BottomRight
    BottomLeft
    LeftTop
    RightTop
    RightBottom
    LeftBottom
)

Orientation values as defined by EXIF.

func DetectOrientation Uses

func DetectOrientation(image *vips.Image) Orientation

DetectOrientation detects the current Image Orientation from the EXIF header.

func (Orientation) Apply Uses

func (orientation Orientation) Apply(image *vips.Image) error

Apply executes a set of operations to change the pixel ordering from orientation to TopLeft.

func (Orientation) Crop Uses

func (orientation Orientation) Crop(ow, oh int, x, y int, iw, ih int) (int, int, int, int)

Crop translates crop parameters from virtual coordinates to match the current physical Orientation.

func (Orientation) Dimensions Uses

func (orientation Orientation) Dimensions(width, height int) (int, int)

Dimensions translates a virtual width and height to match the current physical Orientation.

type SaveOptions Uses

type SaveOptions struct {
    // Format is the Format that an image is saved in. If unspecified, the best output format for a given input image is selected.
    Format Format
    // JPEG or WebP quality for an output image (1-100).
    Quality int
    // Compress is the GZIP compression setting to use for PNG images (1-9).
    Compression int
    // AllowWebp allows automatic selection of WebP format, if reader can support it.
    AllowWebp bool
    // Lossless allows selection of a lossless output format.
    Lossless bool
    // LossyIfPhoto uses a lossy format if it detects that an image is a photo.
    LossyIfPhoto bool
}

SaveOptions specifies how an image should be saved.

Package format imports 4 packages (graph) and is imported by 1 packages. Updated 2016-11-13. Refresh now. Tools for package owners.