imstor: github.com/deiwin/imstor Index | Files

package imstor

import "github.com/deiwin/imstor"

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

Package Files

config.go imstor.go jpeg_format.go png2jpeg.go resizer.go store.go writing.go

Variables

var DefaultResizer = defaultResizer{}

type Config Uses

type Config struct {
    RootPath  string
    CopySizes []Size
    Formats   []Format
}

func NewConfig Uses

func NewConfig(copySizes []Size, formats []Format) *Config

type Format Uses

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 Uses

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 Size Uses

type Size struct {
    Name   string
    Height uint
    Width  uint
}

Size specifies a set of dimensions and a name that a copy of an image will be stored as

type Storage Uses

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 New Uses

func New(conf *Config) Storage

New creates a storage engine using the default Resizer

func NewWithCustomResizer Uses

func NewWithCustomResizer(conf *Config, resizer Resizer) Storage

NewWithCustomResizer creates a storage engine using a custom resizer

Package imstor imports 17 packages (graph) and is imported by 1 packages. Updated 2016-07-16. Refresh now. Tools for package owners.