Skip to content

Repository files navigation

Ivy godoc badgegocover badgeBuild StatusGo Report Card

Assets & Image processing on the fly by libvips

Installation

go get -u github.com/plimble/ivy

#####libvips

OSX

brew install pkg-config
brew tap homebrew/science
brew install vips

Documentation

Sources

File System
source:=ivy.NewFileSystemSource("/path/to/asset")
cache:=ivy.NewFileSystemCache("/path/to/cache")
processor:=ivy.NewGMProcessor()
config:=&ivy.Config{
IsDevelopment: false, //If false, Enable cacheHTTPCache: 66000, //If > 0, Enable HTTP Cache
}
iv:=ivy.New(source, cache, processor, config)
AWS S3
source:=ivy.NewS3Source("accessKey", "secretKey")
cache:=ivy.NewFileSystemCache("/path/to/cache")
processor:=ivy.NewGMProcessor()
config:=&ivy.Config{
IsDevelopment: false, //If false, Enable cacheHTTPCache: 66000, //If > 0, Enable HTTP Cache
}
iv:=ivy.New(source, cache, processor, config)

Cache

You can use file system for caching or set nil for CDN like Cloudfront or disable caching

Server

You can run built-in server (ivy folder) or implement in your server

For more config

./ivy -h
NAME:
Ivy - Assets & Image processing on the fly
USAGE:
Ivy [global options] command [command options] [arguments...]
COMMANDS:
help, h	Shows a list of commands or helpfor one command
GLOBAL OPTIONS:
--url, -u ":4900" server port
--httpcache, -t "0"if cache enable this is http cache in second
--cache, -c enable cache, specific eg, file
--source, -s "file"source of image eg, file, s3
--s3key ifsource is s3, AWS S3 access key [$AWS_ACCESS_KEY]
--s3secret ifsource is s3, AWS S3 secret key [$AWS_SECRET_KEY]
--sourceroot ifsource is file, specific root path of image
--cacheroot if cache is file, specific root path of cache
--help, -h show help
--version, -v print the version
Ace Example
a:=ace.New()
a.GET("/:bucket/:params/*path", func(c*ace.C) {
iv.Get(
c.Params.ByName("bucket"),
c.Params.ByName("params"),
c.Params.ByName("path"),
c.Writer,
c.Request,
)
})
a.Run(":3000")

###Customs

Custom Source
typeSourceinterface {
Load(bucketstring, filenamestring) (*bytes.Buffer, error)
GetFilePath(bucketstring, filenamestring) string
}
Custom Cache
typeCacheinterface {
Save(bucket, filenamestring, params*Params, file []byte) errorLoad(bucket, filenamestring, params*Params) (*bytes.Buffer, error)
Delete(bucket, filenamestring, params*Params) errorFlush(bucketstring) error
}
Custom Processor
typeProcessorinterface {
Process(params*Params, pathstring, file*bytes.Buffer) (*bytes.Buffer, error)
}

Example Request Image

Get image with original size or non image

http://localhost:3000/bucket/_/test.jpg
http://localhost:3000/bucket/0/test.jpg
Original imageAfter image
beforeafter

#####Resize 100x100

http://localhost:3000/bucket/r_100x100/test.jpg
Original imageAfter image
beforeafter

#####Resize width 100px aspect ratio

http://localhost:3000/bucket/r_100x0/test.jpg
Original imageAfter image
beforeafter

#####Crop image 200x200 with default gravity (NorthWest)

http://localhost:3000/bucket/c_200x200/test.jpg
Original imageAfter image
beforeafter

#####Crop with gravity East image 200x200

http://localhost:3000/bucket/c_200x200,g_e/test.jpg
Original imageAfter image
beforeafter

#####Resize 400x400 then crop 200x200 and gravity center

http://localhost:3000/bucket/r_400x400,c_200x200,g_c/test.jpg
Original imageAfter image
beforeafter

#####Quality 100

http://localhost:3000/bucket/q_100/test.jpg
Original imageAfter image
beforeafter

###Params Table

ParamDescription
r_{width}x{height}Resize image, if 0 is aspect ratio
c_{width}x{height}Crop image
g_{direction}Gravity image
q_{quality}Quality image maximum 100

###Gravity position

ParamDescription
nwNorth West
nNorth
neNorth East
wWest
cCenter
eEast
swSouth West
sSouth
seSouth East

###Contributing

If you'd like to help out with the project. You can put up a Pull Request.

About

Ivy assets & Image processing on the fly by GraphicsMagick

Resources

Stars

17 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages