imageserver

package module
v0.0.0-...-0345585 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2014 License: MIT Imports: 4 Imported by: 0

README

Image Server

An image server written in Go (Golang)

Features

  • Http server
  • Resize / convert / process (Graphicsmagick)
  • Cache (Redis, Memcache, in memory)
  • Fully modular

Demo

Normal
http://fuckingfrogs.fr:8080/?source=https://raw.github.com/pierrre/imageserver/master/testdata/small.jpg

Normal

Resize animated gif
http://fuckingfrogs.fr:8080/?source=https://raw.github.com/pierrre/imageserver/master/testdata/animated.gif&width=300&height=300

Resize animated gif

Resize and crop
http://fuckingfrogs.fr:8080/?source=https://raw.github.com/pierrre/imageserver/master/testdata/medium.jpg&width=200&height=200&extent=1&fill=1

Resize and crop

Resize jpeg low quality
http://fuckingfrogs.fr:8080/?source=https://raw.github.com/pierrre/imageserver/master/testdata/large.jpg&width=400&format=jpeg&quality=50

Resize jpeg low quality

Resize huge image (5000x5000)
http://fuckingfrogs.fr:8080/?source=https://raw.github.com/pierrre/imageserver/master/testdata/huge.jpg&width=300&height=300

Resize huge image (5000x5000)

Resize benchmark

go test -bench=. -benchtime=10s ./processor/graphicsmagick
testing: warning: no tests to run
PASS
BenchmarkResizeSmallWorker1-8	    5000	   8188875 ns/op
BenchmarkResizeMediumWorker1-8	    1000	  23143921 ns/op
BenchmarkResizeLargeWorker1-8	     500	  52679041 ns/op
BenchmarkResizeHugeWorker1-8	      50	 389060935 ns/op
BenchmarkResizeAnimatedWorker1-8	      50	 311136430 ns/op
BenchmarkResizeSmallWorker2-8	    5000	   5786665 ns/op
BenchmarkResizeMediumWorker2-8	    1000	  16159015 ns/op
BenchmarkResizeLargeWorker2-8	     500	  36070204 ns/op
BenchmarkResizeHugeWorker2-8	      50	 247750150 ns/op
BenchmarkResizeAnimatedWorker2-8	      50	 221887473 ns/op
BenchmarkResizeSmallWorker4-8	    5000	   5674571 ns/op
BenchmarkResizeMediumWorker4-8	    2000	  13427690 ns/op
BenchmarkResizeLargeWorker4-8	    1000	  29846192 ns/op
BenchmarkResizeHugeWorker4-8	      50	 217280287 ns/op
BenchmarkResizeAnimatedWorker4-8	      50	 243820932 ns/op
BenchmarkResizeSmallWorker8-8	    5000	   4770737 ns/op
BenchmarkResizeMediumWorker8-8	    2000	  12349114 ns/op
BenchmarkResizeLargeWorker8-8	    1000	  27195685 ns/op
BenchmarkResizeHugeWorker8-8	      50	 214468274 ns/op
BenchmarkResizeAnimatedWorker8-8	      50	 200378466 ns/op
ok  	github.com/pierrre/imageserver/processor/graphicsmagick	443.701s

Status

Build Status

Usage / Build

You have to compile/configure your own image server.

See examples:

Documentation

http://godoc.org/github.com/pierrre/imageserver

Help

  • Twitter: @pierredurand87
  • Github issue

TODO

  • more tests
  • add new "parameter error", convert in http
  • source provider
    • dispatch (uri scheme)
    • limit concurrent
    • http timeout
  • processor:
    • native (use "image" package)
    • native imagemagick

Documentation

Overview

Package imageserver provides an image server

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ImageEqual

func ImageEqual(image1, image2 *Image) bool

ImageEqual compares two images and returns true if they are equal

Types

type Error

type Error struct {
	Text string
}

Error represents an error displayable to the end user.

It is used in the http server: the errors of this type are displayed, the others are shown as "internal error".

func NewError

func NewError(text string) *Error

NewError creates an Error

func (*Error) Error

func (err *Error) Error() string

type Image

type Image struct {
	Format string // png, jpeg, bmp, gif, ...
	Data   []byte // raw image data
}

Image represents a raw image

func NewImageUnmarshalBinary

func NewImageUnmarshalBinary(marshalledData []byte) (*Image, error)

NewImageUnmarshalBinary creates a new Image from serialized bytes

func (*Image) MarshalBinary

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

MarshalBinary serializes the Image to bytes

It's very unlikely that it returns an error (impossible?)

func (*Image) UnmarshalBinary

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

UnmarshalBinary unserializes bytes to the Image

type ImageServer

type ImageServer struct {
	Provider
	Processor // optional
}

ImageServer represents an Image server

func (*ImageServer) Get

func (imageServer *ImageServer) Get(parameters Parameters) (*Image, error)

Get returns an Image for given Parameters

The "source" parameter is required.

type ImageServerFunc

type ImageServerFunc func(parameters Parameters) (*Image, error)

ImageServerFunc is a ImageServer func

func (ImageServerFunc) Get

func (f ImageServerFunc) Get(parameters Parameters) (*Image, error)

Get calls the func

type ImageServerInterface

type ImageServerInterface interface {
	Get(Parameters) (*Image, error)
}

ImageServerInterface represents an interface for an Image server

type Parameters

type Parameters map[string]interface{}

Parameters represents parameters used in imageserver package

This is a wrapper around map and provides getter and hash methods

Getter methods return an error if the key does not exist or the type does not match

func (Parameters) Empty

func (parameters Parameters) Empty() bool

Empty returns true if parameters is empty and false otherwise

func (Parameters) Get

func (parameters Parameters) Get(key string) (interface{}, error)

Get returns the value for the key

It returns an error if the value is not found

func (Parameters) GetBool

func (parameters Parameters) GetBool(key string) (bool, error)

GetBool returns the value as a bool for the key

It returns an error if the value is not a bool

func (Parameters) GetInt

func (parameters Parameters) GetInt(key string) (int, error)

GetInt returns the value as an int for the key

It returns an error if the value is not an int

func (Parameters) GetParameters

func (parameters Parameters) GetParameters(key string) (Parameters, error)

GetParameters returns the value as a Parameters for the key

It returns an error if the value is not a Parameters

func (Parameters) GetString

func (parameters Parameters) GetString(key string) (string, error)

GetString returns the value as a string for the key

It returns an error if the value is not a string

func (Parameters) Has

func (parameters Parameters) Has(key string) bool

Has returns true if the key exists and false otherwise

func (Parameters) Keys

func (parameters Parameters) Keys() []string

Keys returns the keys

func (Parameters) Len

func (parameters Parameters) Len() int

Len returns the length

func (Parameters) Set

func (parameters Parameters) Set(key string, value interface{})

Set sets the value for the key

func (Parameters) String

func (parameters Parameters) String() string

String returns the string representation

Keys are sorted alphabetically

type Processor

type Processor interface {
	Process(*Image, Parameters) (*Image, error)
}

Processor represents an Image processor

type Provider

type Provider interface {
	Get(source interface{}, parameters Parameters) (*Image, error)
}

Provider represents an Image provider

Directories

Path Synopsis
_examples
_test
Package _test provides utilities for cache testing
Package _test provides utilities for cache testing
async
Package async provides an asynchronous cache
Package async provides an asynchronous cache
list
Package list provides a list of Image Cache
Package list provides a list of Image Cache
memcache
Package memcache provides a Memcache Image Cache
Package memcache provides a Memcache Image Cache
memory
Package memory provides an in-memory Image Cache
Package memory provides an in-memory Image Cache
redis
Package redis provides a Redis Image Cache
Package redis provides a Redis Image Cache
Package http provides an HTTP Handler for the imageserver package
Package http provides an HTTP Handler for the imageserver package
parser/graphicsmagick
Package graphicsmagick provides a GraphicsMagick http Parser
Package graphicsmagick provides a GraphicsMagick http Parser
parser/list
Package list provides a list of http Parser
Package list provides a list of http Parser
parser/source
Package source provides an http Parser that takes the "source" parameter from query
Package source provides an http Parser that takes the "source" parameter from query
parser/sourcepath
Package sourcepath provides an http Parser that takes the "source" parameter from the path
Package sourcepath provides an http Parser that takes the "source" parameter from the path
processor
graphicsmagick
Package graphicsmagick provides a GraphicsMagick Image Processor
Package graphicsmagick provides a GraphicsMagick Image Processor
limit
Package limit provides an Image Processor that limits the number of concurrent executions
Package limit provides an Image Processor that limits the number of concurrent executions
list
Package list provides a list of Image Processor
Package list provides a list of Image Processor
provider
cache
Package cache provides a cached Image Provider
Package cache provides a cached Image Provider
http
Package http provides a http Image Provider
Package http provides a http Image Provider

Jump to

Keyboard shortcuts

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