imageserver

package module
v0.0.0-...-37a4a7e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2022 License: MIT Imports: 6 Imported by: 0

README

Image Server

An image server toolkit in Go (Golang)

GoDoc Build Status Go Report Card

Features

Examples

Demos

These demos use the "advanced" example.

Click the images to see the URL parameters.

Resize
Options Result
width=200
(preserve aspect ratio)
height=200
(preserve aspect ratio)
width=200&height=200
(change aspect ratio)
width=200&height=200&mode=fit
(fit in 200x200)
width=200&height=200&mode=fill
(fill 200x200 and crop)
Rotate
Options Result
rotation=90
(counterclockwise)
rotation=45&background=ffaa88
(background)
Crop

Format: min_x,min_y|max_x,max_y

Options Result
crop=556,111|2156,1711
crop=956,511|1756,1311
crop=1252,799|1460,1022
Animated GIF
Original Resized
Animated
Spaceship
Gamma correction (more info)
Original Disabled Enabled
Dalai Gamma
Gray squares
Random
Rings
Rules / sucks
Resampling
Resampling Rings Large
Nearest neighbor
Box
Linear
Cubic
Lanczos
Quality
JPEG quality Result
5%
10%
50%
Convert (JPEG to GIF)

Backward compatibility

There is no backward compatibility promises. If you want to use it, vendor it. It's always OK to change things to make things better. The API is not 100% correct in the first commit.

Documentation

Overview

Package imageserver provides an Image server toolkit.

Index

Constants

View Source
const (
	// ImageFormatMaxLen is the maximum length for the Image's format.
	ImageFormatMaxLen = 1 << 8 // 256 B
	// ImageDataMaxLen is the maximum length for the Image's data.
	ImageDataMaxLen = 1 << 30 // 1 GiB
)
View Source
const MIMEOctetStream = "application/octet-stream"

Variables

This section is empty.

Functions

func GetMIME

func GetMIME(extension string) (mime string)

GetMIME returns the content-type of a file extension

func GetMimes

func GetMimes() []string

Types

type Handler

type Handler interface {
	Handle(*Image, Params) (*Image, error)
}

Handler handles an Image and returns an Image.

type HandlerFunc

type HandlerFunc func(*Image, Params) (*Image, error)

HandlerFunc is a Handler func.

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(im *Image, params Params) (*Image, error)

Handle implements Handler.

type HandlerServer

type HandlerServer struct {
	Server
	Handler Handler
}

HandlerServer is a Server implementation that calls a Handler.

func (*HandlerServer) Get

func (srv *HandlerServer) Get(params Params) (*Image, error)

Get implements Server.

type Image

type Image struct {
	// Format is the format used to encode the image.
	//
	// e.g. png, jpeg, bmp, gif, ...
	Format string

	// Data contains the raw data of the encoded image.
	Data []byte

	// e.g. js, css, compress with gzip or brotli
	Encoding string

	// file Modified time
	Modtime time.Time

	// file name
	Name string
}

Image is a raw image.

Binary encoding:

  • Format length (uint32)
  • Format (string)
  • Data length (uint32)
  • Data([]byte)

Numbers are encoded using little-endian order.

func (*Image) MarshalBinary

func (im *Image) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*Image) UnmarshalBinary

func (im *Image) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

It copies data then call UnmarshalBinaryNoCopy().

func (*Image) UnmarshalBinaryNoCopy

func (im *Image) UnmarshalBinaryNoCopy(data []byte) error

UnmarshalBinaryNoCopy is like encoding.BinaryUnmarshaler but does no copy.

The caller must not reuse data after that.

type ImageError

type ImageError struct {
	Message string
}

ImageError is an Image error.

func (*ImageError) Error

func (err *ImageError) Error() string

type ParamError

type ParamError struct {
	Param   string // Nested param path uses "." as separator
	Message string
}

ParamError is an error for a param.

func (*ParamError) Error

func (err *ParamError) Error() string

type Params

type Params map[string]interface{}

Params are params used in imageserver.

This is a wrapper around map[string]interface{} and provides utility methods. It should only contains basic Go types values (string, int float64, ...) or nested Params.

Getter methods return a *ParamError if the key does not exist or the type does not match.

func (Params) Copy

func (params Params) Copy() Params

Copy returns a deep copy of the Params.

func (Params) Empty

func (params Params) Empty() bool

Empty returns true if params is empty and false otherwise.

func (Params) Get

func (params Params) Get(key string) (interface{}, error)

Get returns the value for the key.

func (Params) GetBool

func (params Params) GetBool(key string) (bool, error)

GetBool returns the bool value for the key.

func (Params) GetFloat

func (params Params) GetFloat(key string) (float64, error)

GetFloat returns the float64 value for the key.

func (Params) GetInt

func (params Params) GetInt(key string) (int, error)

GetInt returns the int value for the key.

func (Params) GetInt64

func (params Params) GetInt64(key string) (int64, error)

GetInt64 returns the int64 value for the key.

func (Params) GetParams

func (params Params) GetParams(key string) (Params, error)

GetParams returns the Params value for the key.

func (Params) GetString

func (params Params) GetString(key string) (string, error)

GetString returns the string value for the key.

func (Params) Has

func (params Params) Has(key string) bool

Has returns true if the key exists and false otherwise.

func (Params) Keys

func (params Params) Keys() []string

Keys returns the keys.

func (Params) Len

func (params Params) Len() int

Len returns the length.

func (Params) Set

func (params Params) Set(key string, value interface{})

Set sets the value for the key.

func (Params) String

func (params Params) String() string

String returns the string representation.

Keys are sorted alphabetically.

type Server

type Server interface {
	Get(Params) (*Image, error)
}

Server serves an Image.

func NewLimitServer

func NewLimitServer(s Server, limit int) Server

NewLimitServer creates a new Server that limits the number of concurrent executions.

It uses a buffered channel to limit the number of concurrent executions.

type ServerFunc

type ServerFunc func(Params) (*Image, error)

ServerFunc is a Server func.

func (ServerFunc) Get

func (f ServerFunc) Get(params Params) (*Image, error)

Get implements Server.

Directories

Path Synopsis
Package cache provides a base for an Image cache.
Package cache provides a base for an Image cache.
_test
Package _test provides utilities for imageserver/cache.Cache testing.
Package _test provides utilities for imageserver/cache.Cache testing.
file
Package file provides a disk based cache.
Package file provides a disk based cache.
memcache
Package memcache provides a Memcache imageserver/cache.Cache implementation.
Package memcache provides a Memcache imageserver/cache.Cache implementation.
memory
Package memory provides an in-memory imageserver/cache.Cache implementation.
Package memory provides an in-memory imageserver/cache.Cache implementation.
redis
Package redis provides a Redis imageserver/cache.Cache implementation.
Package redis provides a Redis imageserver/cache.Cache implementation.
examples
advanced
Package advanced provides an advanced example.
Package advanced provides an advanced example.
cache
Package cache provides a cache example.
Package cache provides a cache example.
httpsource
Package httpsource provides a HTTP Source example.
Package httpsource provides a HTTP Source example.
simple
Package simple provides a simple example.
Package simple provides a simple example.
Package graphicsmagick provides a GraphicsMagick imageserver.Handler implementation.
Package graphicsmagick provides a GraphicsMagick imageserver.Handler implementation.
Package http provides a net/http.Handler implementation that wraps a imageserver.Server.
Package http provides a net/http.Handler implementation that wraps a imageserver.Server.
crop
Package crop provides a imageserver/http.Parser implementation for imageserver/image/crop.Processor.
Package crop provides a imageserver/http.Parser implementation for imageserver/image/crop.Processor.
gamma
Package gamma provides a imageserver/http.Parser implementation for imageserver/image/gamma.CorrectionProcessor.
Package gamma provides a imageserver/http.Parser implementation for imageserver/image/gamma.CorrectionProcessor.
gift
Package gift provides imageserver/http.Parser implementations for imageserver/image/gift.
Package gift provides imageserver/http.Parser implementations for imageserver/image/gift.
graphicsmagick
Package graphicsmagick provides a imageserver/http.Parser implementation for imageserver/graphicsmagick.Handler.
Package graphicsmagick provides a imageserver/http.Parser implementation for imageserver/graphicsmagick.Handler.
image
Package image provides imageserver/http.Parser implementations for imageserver/image.
Package image provides imageserver/http.Parser implementations for imageserver/image.
nfntresize
Package nfntresize provides a imageserver/http.Parser implementation for imageserver/image/nfntresize.Processor.
Package nfntresize provides a imageserver/http.Parser implementation for imageserver/image/nfntresize.Processor.
Package image provides a bridge to the Go "image" package.
Package image provides a bridge to the Go "image" package.
_test
Package _test provides utilities for imageserver/image.Encoder testing.
Package _test provides utilities for imageserver/image.Encoder testing.
bmp
Package bmp provides a BMP imageserver/image.Encoder implementation.
Package bmp provides a BMP imageserver/image.Encoder implementation.
crop
Package crop provides a imageserver/image.Processor implementation that allows to crop Image.
Package crop provides a imageserver/image.Processor implementation that allows to crop Image.
gamma
Package gamma provides gamma imageserver/image.Processor implementations.
Package gamma provides gamma imageserver/image.Processor implementations.
gif
Package gif provides GIF imageserver/image.Encoder|Processor and imageserver.Handler implementations.
Package gif provides GIF imageserver/image.Encoder|Processor and imageserver.Handler implementations.
gift
Package gift provides imageserver/image.Processor implementations for GIFT.
Package gift provides imageserver/image.Processor implementations for GIFT.
internal
Package internal provides utilities functions used in the image package.
Package internal provides utilities functions used in the image package.
jpeg
Package jpeg provides a JPEG imageserver/image.Encoder implementation.
Package jpeg provides a JPEG imageserver/image.Encoder implementation.
nfntresize
Package nfntresize provides a nfnt/resize imageserver/image.Processor implementation.
Package nfntresize provides a nfnt/resize imageserver/image.Processor implementation.
png
Package png provides a PNG imageserver/image.Encoder implementation.
Package png provides a PNG imageserver/image.Encoder implementation.
tiff
Package tiff provides a TIFF imageserver/image.Encoder implementation.
Package tiff provides a TIFF imageserver/image.Encoder implementation.
Package source provides a imageserver.Server implementation that forwards calls to the underlying Server with only the "source" param.
Package source provides a imageserver.Server implementation that forwards calls to the underlying Server with only the "source" param.
file
Package file provides a imageserver.Server implementation that get the Image from a file.
Package file provides a imageserver.Server implementation that get the Image from a file.
http
Package http provides a imageserver.Server implementation that gets the Image from an HTTP URL.
Package http provides a imageserver.Server implementation that gets the Image from an HTTP URL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL