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.NewImageFromFile(imagePath) if err != nil { panic(err) } thumbBytes, err := gen.CreateThumbnail(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 ¶
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 generator configuration to be used when creating thumbnails.
func NewGenerator ¶ added in v0.1.2
NewGenerator returns an instance of a thumbnail generator with a given configuration.
func (*Generator) CreateThumbnail ¶ added in v0.1.3
CreateThumbnail generates a thumbnail.
func (*Generator) NewImageFromByteArray ¶ added in v0.1.3
NewImageFromByteArray reads in an image from a byte array and populates an Image object. That new Image object is returned along with any errors that occur during the operation.
func (*Generator) NewImageFromFile ¶ added in v0.1.3
NewImageFromFile reads in an image file from the file system and populates an Image object. That new Image object is returned along with any errors that occur during the operation.
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.