imgwizard

package module
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2017 License: MIT Imports: 19 Imported by: 0

README

ImgWizard - fast, light, easy to use

Build Status

What is it?

ImgWizard is a small server written in Go as faster alternative for thumbor

What it can do?

  • Fetch original image from:
    • local file system
    • remote media storage
    • microsoft azure
    • amazon s3
  • Resize it
  • Crop it
  • Change quality
  • Cache resized image and fetch it on next request:
    • to file system
    • to Amazon S3
    • to Microsoft Azure Storage
  • Return WebP images if browser supports it

How to use?

http://{server}/{mark}/{storage}/{size}/{path_to_file}?{params}

  • server - imgwizard server addr
  • mark - mark for url (can be used for nginx proxying)
  • storage - "loc" (local file system) or "rem" (remote media) or "az" (azure storage)
  • size - "320x240" or "320x" or "x240"
  • path_to_file - path to original file (without "http://")
  • params - query parameters

#####Params:#####

  • crop - sides fixed when cropping (top, right, bottom, left)
  • q - result image quality (default set from command line "-q")
  • original ("true" or "false", default - "false") - return original image without processing and saving to cache
Example:

http://192.168.0.1:4444/images/rem/462x/media.google.com/uploads/images/1/test.jpg?crop=top,left&q=90

How to install?

Installing libvips

VIPS is a free image processing system. Compared to similar libraries, VIPS is fast and does not need much memory, see the Speed and Memory Use page. As well as JPEG, TIFF, PNG and WebP images, it also supports scientific formats like FITS, OpenEXR, Matlab, Analyze, PFM, Radiance, OpenSlide and DICOM (via libMagick). (© vips wiki)

Mac OS

$ brew tap homebrew/science

$ brew install vips --with-webp

Debian based

$ sudo apt-get install libvips-dev

RedHat

$ yum install libwebp-devel glib2-devel libpng-devel libxml2-devel libjpeg-devel

$ wget http://www.vips.ecs.soton.ac.uk/supported/7.38/vips-7.38.5.tar.gz

$ tar xvzf vips-7.38.5.tar.gz; cd vips-7.38.5

$ ./configure

$ make

$ make install

$ echo '/usr/local/lib' > /etc/ld.so.conf.d/libvips.conf

$ ldconfig -v

Installing imgwizard
  • go get github.com/shifr/imgwizard
  • export PATH=$PATH:$GOPATH/bin if you haven't done it before
Running imgwizard
  • imgwizard - run server without restrictions

You will see "ImgWizard started..."

Check imgwizard work after server start

###Doesn't work?### Try to add PKG_CONFIG_PATH into environment:

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/lib/pkgconfig"

Parameters on start?

DEBUG_ENABLED=1 WARNING_ENABLED=1 imgwizard -l localhost:9000 -c /tmp/my_cache_dir -thumb /tmp/404.jpg -d /v1/uploads,/v2/uploads -m media1.com,media2.com -s 100x100,480x,x200 -q 80 -mark imgw -nodes 127.0.0.1:8071,127.0.0.1:8072 -no-cache-key 123

####ENV####

  • DEBUG_ENABLED: show all debug messages
  • WARNING_ENABLED: show warning messages (when image not found/processed)

####Flags###

  • -l: Address to listen on (default - "localhost:8070")
  • -s3-b: Amazon S3 bucket name where cache will be located (for current wizard node).
  • -az: Microsoft Azure Storage container name where cache will be located (for current wizard node).
  • -c: directory for cached files (WORKS if "-s3-b" not specified, default - "/tmp/imgwizard")
  • -thumb: absolute path to default image if original not found (optional)
  • -m: comma separated list of allowed media (default - all enabled)
  • -s: comma separated list of allowed sizes (default - all enabled)
  • -d: comma separated list of directories to search original file
  • -q: resized image quality (default - 80)
  • -mark: mark (default - images)
  • -nodes: comma separated list of other imgwizard nodes for cache check (see nodes)
  • -no-cache-key: secret key that must be equal X-No-Cache value from request header to prevent reading from cache

####Use Amazon S3 for caching OR as a storage for original image?#### Then you should specify more ENV variables:

  • AWS_REGION: where to send requests. (Example: "us-west-2") //Required
  • AWS_ACCESS_KEY_ID: your access key id
  • AWS_SECRET_ACCESS_KEY: your secret access key

####Use Azure Storage for caching OR as a storage for original image?#### Then you should specify more ENV variables:

  • AZURE_ACCOUNT_NAME: your azure account name
  • AZURE_ACCOUNT_KEY: your key for SDK auth

Who are already using it?

Plans?

Yes, a lot.

Documentation

Index

Constants

View Source
const (
	VERSION                  = 1.5
	DEFAULT_POOL_SIZE        = 100000
	WEBP_HEADER              = "image/webp"
	JPEG                     = "image/jpeg"
	PNG                      = "image/png"
	AZURE_ACCOUNT_NAME       = "AZURE_ACCOUNT_NAME"
	AZURE_ACCOUNT_KEY        = "AZURE_ACCOUNT_KEY"
	AWS_REGION               = "AWS_REGION"
	AWS_ACCESS_KEY_ID        = "AWS_ACCESS_KEY_ID"
	AWS_SECRET_ACCESS_KEY    = "AWS_SECRET_ACCESS_KEY"
	ONLY_CACHE_HEADER        = "X-Cache-Only"
	NO_CACHE_HEADER          = "X-No-Cache"
	CACHE_DESTINATION_HEADER = "X-Cache-Destination"
)

Variables

View Source
var (
	DEBUG           = false
	WARNING         = false
	ClientConfirmed = false
	DEFAULT_QUALITY = 80

	Crop = map[string]vips.Gravity{
		"top":    vips.NORTH,
		"right":  vips.EAST,
		"bottom": vips.SOUTH,
		"left":   vips.WEST,
	}
	ResizableImageTypes = []string{"image/jpeg", "image/png"}

	Version            bool
	ListenAddr         string
	AllowedMedia       string
	AllowedSizes       string
	CacheDir           string
	S3BucketName       string
	AzureContainerName string
	Default404         string
	DirsToSearch       string
	Mark               string
	NoCacheKey         string
	Nodes              string
	Quality            int

	ChanPool       chan int
	Cache          *cache.Cache
	Options        vips.Options
	GlobalSettings Settings
	AzureClient    storage.BlobStorageClient
	S3Client       *s3.S3
)

Functions

func FetchImage

func FetchImage(rw http.ResponseWriter, req *http.Request)

func Transform

func Transform(img_buff *[]byte, ctx *Context)

Types

type Context

type Context struct {
	NoCache        bool
	OnlyCache      bool
	IsOriginal     bool
	Width          int
	Height         int
	AzureContainer string
	S3Bucket       string
	Path           string
	RequestURI     string
	CachePath      string
	Storage        string
	SubPath        string
	OrigImage      string
	Query          string

	Options vips.Options
}

func (*Context) Fill

func (c *Context) Fill(req *http.Request)

type RegexpHandler

type RegexpHandler struct {
	// contains filtered or unexported fields
}

func (*RegexpHandler) HandleFunc

func (h *RegexpHandler) HandleFunc(pattern *regexp.Regexp, handler func(http.ResponseWriter, *http.Request))

func (*RegexpHandler) ServeHTTP

func (h *RegexpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Route

type Route struct {
	// contains filtered or unexported fields
}

type Settings

type Settings struct {
	Scheme       string
	AllowedSizes []string
	AllowedMedia []string
	Directories  []string
	Nodes        []string
	UrlExp       *regexp.Regexp
}

func (*Settings) Load

func (s *Settings) Load()

loadSettings loads settings from command-line

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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