Documentation ¶
Overview ¶
Package imstor enables you to create copies (or thumbnails) of your images and stores them along with the original image on your filesystem. The image and its copies are are stored in a file structure based on the (zero-prefixed, decimal) CRC 64 checksum of the original image. The last 2 characters of the checksum are used as the lvl 1 directory name.
Example folder name and contents, given the checksum 08446744073709551615 and sizes named "small" and "large":
/configured/root/path/15/08446744073709551615/original.jpeg /configured/root/path/15/08446744073709551615/small.jpeg /configured/root/path/15/08446744073709551615/large.jpeg
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultResizer = defaultResizer{}
Functions ¶
This section is empty.
Types ¶
type Format ¶
type Format interface { DecodableMediaType() string Decode(io.Reader) (image.Image, error) Encode(io.Writer, image.Image) error EncodedExtension() string }
A Format describes how an image of a certaing mimetype can be decoded and then encoded.
var JPEGFormat Format = jpegFormat{}
JPEGFormat decodes a jpeg image and encodes it as a JPEG with the extension jpg
var PNG2JPEG Format = png2JPEG{}
PNG2JPEG format decodes an image from the PNG format and encodes it as a JPEG
type Resizer ¶
type Resizer interface { // Resize should scale an image to new width and height. If one of the // parameters width or height is set to 0, its size will be calculated so that // the aspect ratio is that of the originating image. Resize(width, height uint, i image.Image) image.Image // Thumbnail should downscale provided image to max width and height preserving // original aspect ratio. It should return original image, without processing, // if original sizes are already smaller than the provided constraints. Thumbnail(maxWidth, maxHeight uint, i image.Image) image.Image }
A Resizer can resize an image into the given dimensions
type Storage ¶
type Storage interface { Store(mediaType string, data []byte) error StoreDataURL(string) error Checksum([]byte) string ChecksumDataURL(string) (string, error) PathFor(checksum string) (string, error) PathForSize(checksum, size string) (string, error) HasSizesForChecksum(checksum string, sizes []string) (bool, error) GetSize(checksum, size string) (image.Image, error) }
Storage is the engine that can be used to store images and retrieve their paths
func NewWithCustomResizer ¶
NewWithCustomResizer creates a storage engine using a custom resizer