Documentation ¶
Overview ¶
Package thumbnail provides a method to create thumbnails from images.
Example ¶
var config = Generator{ DestinationPath: "", DestinationPrefix: "thumb_", Scaler: "CatmullRom", } imagePath := "path/to/image.jpg" dest := "path/to/thumb_image.jpg" gen := NewGenerator(config) i, err := gen.NewImage(imagePath) if err != nil { panic(err) } thumbBytes, err := gen.Create(i) if err != nil { panic(err) } err = ioutil.WriteFile(dest, thumbBytes, 0644) if err != nil { panic(err) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrInvalidMimeType is returned when a non-image content type is // detected. ErrInvalidMimeType = errors.New("invalid mimetype") // ErrInvalidScaler is returned when an unrecognized scaler is passed to the Generator. ErrInvalidScaler = errors.New("invalid scaler") )
Functions ¶
This section is empty.
Types ¶
type Dimensions ¶ added in v0.1.2
type Dimensions struct { // Width is the width of an image in pixels. Width int // Height is the height on an image in pixels. Height int // X is the right-most X-coordinate. X int // Y is the top-most Y-coordinate. Y int }
Dimensions stores dimensional information for an Image.
type Generator ¶ added in v0.1.2
type Generator struct { // Width is the destination thumbnail width. Width int // Height is the destination thumbnail height. Height int // DestinationPath is the dentination thumbnail path. DestinationPath string // DestinationPrefix is the prefix for the destination thumbnail filename. DestinationPrefix string // Scaler is the scaler to be used when generating thumbnails. Scaler string }
Generator registers a geneator configuration to be used when creating thumbnails.
func NewGenerator ¶ added in v0.1.2
NewGenerator creates a new thumbnail generator and its configuration.
type Image ¶
type Image struct { // Path is a path to an image. Path string // ContentType is the content type of the image. ContentType string // Data is the image data in a byte-array Data []byte // Size is the length of Data Size int // Current stores the existing image's dimentions Current Dimensions // Future store the new thumbnail dimensions. Future Dimensions }
An Image is an image and information about it.
Click to show internal directories.
Click to hide internal directories.