format

package
v2.9.275 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

README

Fotomat Format

Go-based API making use of Fotomat's vips wrapper to allow loading, saving, and metadata extraction from the JPEG, PNG, GIF, and WebP file formats.

Also see:

Documentation

Index

Constants

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

Variables

View Source
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")
)
View Source
var ErrInvalidSaveFormat = errors.New("invalid save format")

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

Functions

func Save

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

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

Types

type Format

type Format int

Format of compressed image.

const (
	Unknown Format = iota
	Jpeg
	Png
	Gif
	Webp
	Tiff
	Pdf
	Svg
)

Format of compressed image.

func DetectFormat

func DetectFormat(blob []byte) Format

DetectFormat detects the Format of the supplied byte slice.

func (Format) CanLoadBytes

func (format Format) CanLoadBytes() bool

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

func (Format) CanLoadFile

func (format Format) CanLoadFile() bool

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

func (Format) LoadBytes

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

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

func (Format) LoadFile

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

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

func (Format) MetadataBytes

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

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

func (format Format) String() string

String returns the mime type of given image format.

type Metadata

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

Metadata is the currently-known metadata about an Image.

func MetadataBytes

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

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

func MetadataImage

func MetadataImage(image *vips.Image) Metadata

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

type Orientation

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

func DetectOrientation(image *vips.Image) Orientation

DetectOrientation detects the current Image Orientation from the EXIF header.

func (Orientation) Apply

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

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

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

func (Orientation) Dimensions

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

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

type SaveOptions

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL