Documentation
¶
Index ¶
- Variables
- type BoltStoreParams
- type Hasher
- type ImageInfo
- type ImageParams
- type Imagine
- func (i *Imagine) Delete(filename string) error
- func (i *Imagine) Get(filename string, params *ImageParams) (*ProcessedImage, error)
- func (i *Imagine) GetHandlerFunc() http.HandlerFunc
- func (i *Imagine) ListImages() ([]ImageInfo, error)
- func (i *Imagine) ParamsFromQueryString(query string) (*ImageParams, error)
- func (i *Imagine) Upload(data []byte) (string, error)
- func (i *Imagine) UploadHandlerFunc() http.HandlerFunc
- type LocalStoreParams
- type MemoryStore
- type MemoryStoreParams
- type Params
- type ProcessedImage
- type SQLiteStoreParams
- type Store
Constants ¶
This section is empty.
Variables ¶
var ErrImageNotFound = errors.New("image not found")
var ErrKeyNotFound = errors.New("key not found")
Functions ¶
This section is empty.
Types ¶
type BoltStoreParams ¶
type BoltStoreParams struct {
Path string
}
BoltStoreParams are the parameters for creating a new BoltStore
type Hasher ¶
Hasher describes the hashing algorithm used to generate the image name. The default implementation is MD5Hasher. You can implement your own hashing algorithm by implementing this interface. For example, you can use SHA256 instead of MD5. You can also use a combination of hashing algorithms.
type ImageInfo ¶
type ImageInfo struct {
Hash string
Filename string
Size int64
Width int
Height int
Format string
CreatedAt string
}
ImageInfo contains metadata about a stored image
type ImageParams ¶
type ImageParams struct {
Width, Height int
// Quality is the quality of the image to be returned (1-100)
Quality int
// Format is the format of the image to be returned
Format string
// Thumbnail is the size of the thumbnail to be returned
Thumbnail int
// Fit mode: cover, contain, fill, inside, outside
Fit string
// Rotation angle in degrees (0, 90, 180, 270)
Rotate int
// Flip: h (horizontal), v (vertical), both
Flip string
// Blur sigma value (0.3 to 1000)
Blur float64
// Sharpen sigma value
Sharpen float64
// Convert to grayscale
Grayscale bool
// Gravity for smart cropping: center, north, south, east, west, etc.
Gravity string
// Preset for common configurations: thumb, small, medium, large, hero
Preset string
}
Image params are the requested params to modify an image when retriving it
type Imagine ¶
type Imagine struct {
// contains filtered or unexported fields
}
Imagine is our main application struct
func (*Imagine) Get ¶
func (i *Imagine) Get(filename string, params *ImageParams) (*ProcessedImage, error)
Get is the main entry point for the Imagine application. It returns the image as an array of bytes
func (*Imagine) GetHandlerFunc ¶
func (i *Imagine) GetHandlerFunc() http.HandlerFunc
ProcessHandler handles the generation of images
func (*Imagine) ListImages ¶
ListImages returns information about all stored images Note: This requires the storage to be SQLite for now
func (*Imagine) ParamsFromQueryString ¶
func (i *Imagine) ParamsFromQueryString(query string) (*ImageParams, error)
ParamsFromQueryString returns an ImageParams given a query string
func (*Imagine) UploadHandlerFunc ¶
func (i *Imagine) UploadHandlerFunc() http.HandlerFunc
UploadHandler handles the upload of images
type LocalStoreParams ¶
type LocalStoreParams struct {
// Path is the path to the directory where the files will be stored
Path string
// TTL is the time to live for the file in seconds
// This is to be set if you want to use this store as a caching mechanism
TTL time.Duration
}
LocalStoreParams are the parameters for creating a new LocalStore
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
InMemoryStorage is a storage implementation that stores data in memory This should only be used for testing
func (*MemoryStore) Close ¶
func (m *MemoryStore) Close() error
func (*MemoryStore) Delete ¶
func (m *MemoryStore) Delete(key string) error
type MemoryStoreParams ¶
type Params ¶
type Params struct {
Cache Store
Storage Store
Hasher Hasher
// MaxImageSize is the maximum size of an image in bytes
MaxImageSize int
}
Params are the parameters used to create a new Imagine application
type ProcessedImage ¶
ProcessedImage is the result of processing an image
type SQLiteStoreParams ¶
type Store ¶
type Store interface {
Set(key string, data []byte) error
Get(key string) (data []byte, ok bool, err error)
Delete(key string) error
io.Closer
}
Store is an interface for a key-value store. This interface is used by both the cache and the storage backends. Given the huge overlap between them it makes sense to have a common interface. For the Cache layer things like key expiration can be set at the store implementation level.
func NewBoltStore ¶
func NewBoltStore(params BoltStoreParams) (Store, error)
NewBoltStore creates a new BoltStore
func NewInMemoryStorage ¶
func NewInMemoryStorage(params MemoryStoreParams) Store
func NewLocalStorage ¶
func NewLocalStorage(params LocalStoreParams) (Store, error)
func NewRedisStore ¶
func NewRedisStore() Store
func NewSQLiteStorage ¶
func NewSQLiteStorage(params SQLiteStoreParams) (Store, error)
