fotomat: github.com/die-net/fotomat/thumbnail Index | Files

package thumbnail

import "github.com/die-net/fotomat/thumbnail"

Index

Package Files

icc.go init.go options.go pool.go proxy.go thumbnail.go utils.go

Constants

const (
    // DefaultAccept is the default Accept header sent on upstream requests.
    DefaultAccept = "image/jpeg,image/*;q=0.6"
    // DefaultServer is the default Server header sent with responses.
    DefaultServer = "Fotomat"
    // DefaultUserAgent is the default User-Agent header sent on upstream requests.
    DefaultUserAgent = "Fotomat (http://fotomat.org)"
)

Variables

var (
    // ErrBadOption is returned when option values are out of range.
    ErrBadOption = errors.New("Bad option specified")
    // ErrTooBig is returned when an image is too wide or tall.
    ErrTooBig = errors.New("Image is too wide or tall")
    // ErrTooSmall is returned when an image is too small.
    ErrTooSmall = errors.New("Image is too small")
)
var (
    // ErrAborted means the operation wasn't executed because the
    // Request.Aborted channel was closed by the caller.
    ErrAborted = errors.New("Thumbnail request aborted")
)

func Thumbnail Uses

func Thumbnail(blob []byte, o Options) ([]byte, error)

Thumbnail scales or crops a compressed image blob according to the Options specified in o and returns a compressed image. Should be called from a thread pool with runtime.LockOSThread() locked.

type Options Uses

type Options struct {
    // Width and Height are the optional maximum sizes of output image,
    // in pixels.  If Crop is false, the original aspect ratio is
    // preserved and the more restrictive of Width or Height are used.
    Width  int
    Height int
    // Crop enables crop mode, where exact supplied Width:Height aspect
    // ratio is preserved and excess pixels are trimmed from the sides.
    Crop bool
    // MaxBufferPixels specifies how large of an intermediate image
    // buffer to allow, in pixels. RAM usage will be a few bytes per pixel.
    MaxBufferPixels int
    // Sharpen runs a mild sharpening pass on downsampled images.
    Sharpen bool
    // BlurSigma performs a gaussian blur with specified sigma.
    BlurSigma float64
    // FastResize reduces output image quality in some cases in favor of speed.
    FastResize bool
    // MaxQueueDuration limits the amount of time spent in a queue before processing starts.
    MaxQueueDuration time.Duration
    // MaxProcessingDuration limits the amount of time processing an
    // image, after which it is assumed the operation has crashed and
    // the server aborts, killing all outstanding requests.
    MaxProcessingDuration time.Duration
    // Save specifies the format.SaveOptions to use when compressing the modified image.
    Save format.SaveOptions
}

Options specifies how a Thumbnail operation should modify an image.

func OptionsFromJSON Uses

func OptionsFromJSON(j []byte) (Options, error)

OptionsFromJSON returns Options from a JSON representation of it.

func (Options) Check Uses

func (o Options) Check(m format.Metadata) (Options, error)

Check verifies Options against Metadata and returns a modified Options or an error.

func (Options) ToJSON Uses

func (o Options) ToJSON() ([]byte, error)

ToJSON returns a compact JSON representation of Options.

type Pool Uses

type Pool struct {
    RequestCh chan *Request
    // contains filtered or unexported fields
}

Pool represents a Thumbnail worker pool. VIPS keeps thread-local caches, which we retain control over through a combination of a pool of worker goroutines and using runtime.LockOSThread() within those workers.

func NewPool Uses

func NewPool(workers, queueLen int) *Pool

NewPool creates a Thumbnail worker pool with a given number of worker threads and queue length.

func (*Pool) Close Uses

func (p *Pool) Close()

Close shuts down the worker pool and waits for remaining work to be done.

func (*Pool) Thumbnail Uses

func (p *Pool) Thumbnail(blob []byte, options Options, aborted <-chan bool) ([]byte, error)

Thumbnail is a blocking wrapper that executes thumbnail.Thumbnail requests in a pool of worker threads. Work is skipped if aborted is closed while the request is queued.

type Proxy Uses

type Proxy struct {
    Director  func(*http.Request) (Options, int)
    Client    *http.Client
    Accept    string
    Server    string
    UserAgent string
    // contains filtered or unexported fields
}

Proxy represents an HTTP proxy that can optionally run its contents through Thumbnail. Must be created with NewProxy.

func NewProxy Uses

func NewProxy(director func(*http.Request) (Options, int), pool *Pool, maxActive int, client *http.Client) *Proxy

NewProxy creates a Proxy object, with a given Director, Pool, upper limit on images held in RAM, and http.Client.

func (*Proxy) Close Uses

func (p *Proxy) Close()

Close shuts down a Proxy.

func (*Proxy) ServeHTTP Uses

func (p *Proxy) ServeHTTP(w http.ResponseWriter, or *http.Request)

ServeHTTP serves an HTTP request for a given Proxy, using Director to parse the request, fetching an image, calling pool.Thumbnail on it, and returning the result.

type Request Uses

type Request struct {
    Blob       []byte
    Options    Options
    Aborted    <-chan bool
    ResponseCh chan<- *Response
}

Request to be sent to Pool.RequestCh to queue a Thumbnail operation.

type Response Uses

type Response struct {
    Blob  []byte
    Error error
}

Response sent to Request.ResponseCh when the Thumbnail operation is done.

Package thumbnail imports 18 packages (graph). Updated 2016-11-13. Refresh now. Tools for package owners.