images

package
v0.0.0-...-2d5464a Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2015 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScaledDimensions

func ScaledDimensions(w, h, mw, mh int) (newWidth int, newHeight int)

ScaledDimensions returns the newWidth and newHeight obtained when an image of dimensions w x h has to be rescaled under mw x mh, while conserving the proportions. It returns 1,1 if any of the parameter is 0.

func ThumbnailVersion

func ThumbnailVersion() string

ThumbnailVersion returns a string safe for URL query components which is a generation number. Whenever the thumbnailing code is updated, so will this string. It should be placed in some URL component (typically "tv").

Types

type Config

type Config struct {
	Width, Height int
	Format        string
	Modified      bool // true if Decode actually rotated or flipped the image.
}

Config is like the standard library's image.Config as used by DecodeConfig.

func Decode

func Decode(r io.Reader, opts *DecodeOpts) (image.Image, Config, error)

Decode decodes an image from r using the provided decoding options. The Config returned is similar to the one from the image package, with the addition of the Modified field which indicates if the image was actually flipped, rotated, or scaled. If opts is nil, the defaults are used.

func DecodeConfig

func DecodeConfig(r io.Reader) (Config, error)

DecodeConfig returns the image Config similarly to the standard library's image.DecodeConfig with the addition that it also checks for an EXIF orientation, and sets the Width and Height as they would visibly be after correcting for that orientation.

type DecodeOpts

type DecodeOpts struct {
	// Rotate specifies how to rotate the image.
	// If nil, the image is rotated automatically based on EXIF metadata.
	// If an int, Rotate is the number of degrees to rotate
	// counter clockwise and must be one of 0, 90, -90, 180, or
	// -180.
	Rotate interface{}

	// Flip specifies how to flip the image.
	// If nil, the image is flipped automatically based on EXIF metadata.
	// Otherwise, Flip is a FlipDirection bitfield indicating how to flip.
	Flip interface{}

	// MaxWidgth and MaxHeight optionally specify bounds on the
	// image's size. Rescaling is done before flipping or rotating.
	// Proportions are conserved, so the smallest of the two is used
	// as the decisive one if needed.
	MaxWidth, MaxHeight int

	// ScaleWidth and ScaleHeight optionally specify how to rescale the
	// image's dimensions. Rescaling is done before flipping or rotating.
	// Proportions are conserved, so the smallest of the two is used
	// as the decisive one if needed.
	// They overrule MaxWidth and MaxHeight.
	ScaleWidth, ScaleHeight float32
}

type FlipDirection

type FlipDirection int

The FlipDirection type is used by the Flip option in DecodeOpts to indicate in which direction to flip an image.

const (
	FlipVertical FlipDirection = 1 << iota
	FlipHorizontal
)

FlipVertical and FlipHorizontal are two possible FlipDirections values to indicate in which direction an image will be flipped.

Directories

Path Synopsis
Package fastjpeg uses djpeg(1), from the Independent JPEG Group's (www.ijg.org) jpeg package, to quickly down-sample images on load.
Package fastjpeg uses djpeg(1), from the Independent JPEG Group's (www.ijg.org) jpeg package, to quickly down-sample images on load.
Package resize resizes images.
Package resize resizes images.

Jump to

Keyboard shortcuts

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