Assets & Image processing on the fly by libvips
go get -u github.com/plimble/ivy
#####libvips
OSX
brew install pkg-config
brew tap homebrew/science
brew install vips
source := ivy.NewFileSystemSource("/path/to/asset")
cache := ivy.NewFileSystemCache("/path/to/cache")
processor := ivy.NewGMProcessor()
config := &ivy.Config{
IsDevelopment: false, //If false, Enable cache
HTTPCache: 66000, //If > 0, Enable HTTP Cache
}
iv := ivy.New(source, cache, processor, config)
source := ivy.NewS3Source("accessKey", "secretKey")
cache := ivy.NewFileSystemCache("/path/to/cache")
processor := ivy.NewGMProcessor()
config := &ivy.Config{
IsDevelopment: false, //If false, Enable cache
HTTPCache: 66000, //If > 0, Enable HTTP Cache
}
iv := ivy.New(source, cache, processor, config)
You can use file system for caching or set nil
for CDN like Cloudfront or disable caching
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 help for 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 if source is s3, AWS S3 access key [$AWS_ACCESS_KEY]
--s3secret if source is s3, AWS S3 secret key [$AWS_SECRET_KEY]
--sourceroot if source 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
type Source interface {
Load(bucket string, filename string) (*bytes.Buffer, error)
GetFilePath(bucket string, filename string) string
}
type Cache interface {
Save(bucket, filename string, params *Params, file []byte) error
Load(bucket, filename string, params *Params) (*bytes.Buffer, error)
Delete(bucket, filename string, params *Params) error
Flush(bucket string) error
}
type Processor interface {
Process(params *Params, path string, file *bytes.Buffer) (*bytes.Buffer, error)
}
Get image with original size or non image
http://localhost:3000/bucket/_/test.jpg
http://localhost:3000/bucket/0/test.jpg
Original image | After image |
---|---|
#####Resize 100x100
http://localhost:3000/bucket/r_100x100/test.jpg
Original image | After image |
---|---|
#####Resize width 100px aspect ratio
http://localhost:3000/bucket/r_100x0/test.jpg
Original image | After image |
---|---|
#####Crop image 200x200 with default gravity (NorthWest)
http://localhost:3000/bucket/c_200x200/test.jpg
Original image | After image |
---|---|
#####Crop with gravity East image 200x200
http://localhost:3000/bucket/c_200x200,g_e/test.jpg
Original image | After image |
---|---|
#####Resize 400x400 then crop 200x200 and gravity center
http://localhost:3000/bucket/r_400x400,c_200x200,g_c/test.jpg
Original image | After image |
---|---|
#####Quality 100
http://localhost:3000/bucket/q_100/test.jpg
Original image | After image |
---|---|
###Params Table
Param | Description |
---|---|
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
Param | Description |
---|---|
nw | North West |
n | North |
ne | North East |
w | West |
c | Center |
e | East |
sw | South West |
s | South |
se | South East |
###Contributing
If you'd like to help out with the project. You can put up a Pull Request.