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)
}
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 ¶
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 ¶
type Generator struct {
// Width is the destination thumbnail width.
Width int
// Height is the destination thumbnail height.
Height int
// DestinationPath is the destination 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 ¶
NewGenerator returns an instance of a thumbnail generator with a given configuration.
func (*Generator) CreateThumbnail ¶
CreateThumbnail generates a thumbnail.
func (*Generator) NewImageFromByteArray ¶
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.
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 dimensions
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.