项目作者: vanng822

项目描述 :
Middleware/handler for scaling image in golang
高级语言: Go
项目地址: git://github.com/vanng822/imgscale.git
创建时间: 2014-12-20T15:33:22Z
项目社区:https://github.com/vanng822/imgscale

开源协议:MIT License

下载


imgscale

Middleware/handler for scaling image in golang. Use for serving images in different formats. Can use as middleware which is compitable with http.Handler

  • Crop & Scale
  • Autorotate
  • Watermark

Warning: image processing is very resource consuming. If you use this in production you should put a cache server in front, such as Varnish.

Demo server

http://imgscale.isgoodness.com/ is set up with arbitrary remote image. Please be nice!

Formats: 100x100, 100x0, 0x360, 0x170, originalx1, original

And the url will be http://imgscale.isgoodness.com/img/FORMAT/REMOTE_IMAGE

Check out forest waterfall

alt forest waterfall

Dependencies

You need to install ImageMagick first.

MacPorts

  1. sudo port install ImageMagick

Homebrew

  1. brew install imagemagick

Ubuntu/Debian

  1. sudo apt-get install libmagickwand-dev

ImageMagick binding

  1. go get github.com/vanng822/imgscale/imagick

Install

  1. go get github.com/vanng822/imgscale/imgscale

Example

  1. // r2router: github.com/vanng822/r2router
  2. app := r2router.NewSeeforRouter()
  3. handler := imgscale.Configure("./config/formats.json")
  4. defer handler.Cleanup()
  5. app.WrapHandler(handler.ServeHTTP)
  6. go http.ListenAndServe(fmt.Sprintf("%s:%d", "127.0.0.1", 8080), app)
  7. // Negroni
  8. app := negroni.New()
  9. handler := imgscale.Configure("./config/formats.json")
  10. // Free C pointers and terminate MagickWand environment
  11. defer handler.Cleanup()
  12. n.UseHandler(handler)
  13. go http.ListenAndServe(fmt.Sprintf("%s:%d", "127.0.0.1", 8080), app)
  14. // Martini
  15. app := martini.Classic()
  16. handler := imgscale.Configure("./config/formats.json")
  17. defer handler.Cleanup()
  18. app.Use(handler.ServeHTTP)
  19. go http.ListenAndServe(fmt.Sprintf("%s:%d", "127.0.0.1", 8080), app)
  20. // http.Handler
  21. handler := imgscale.Configure("./config/formats.json")
  22. defer handler.Cleanup()
  23. http.Handle("/", handler)
  24. http.ListenAndServe(fmt.Sprintf("%s:%d", "127.0.0.1", 8080), nil)

GoDoc

GoDoc

Try it out

checkout

  1. git clone https://github.com/vanng822/imgscale.git

install dependencies

  1. go get github.com/gographics/imagick/imagick
  2. go get github.com/vanng822/imgscale/imgscale
  3. go get github.com/go-martini/martini
  4. go get github.com/codegangsta/negroni

run application

  1. go run example/all.go

browse it

  1. http://127.0.0.1:8080/img/100x100/kth.jpg
  2. http://127.0.0.1:8081/img/100x100/http://127.0.0.1:8080/img/original/kth.jpg
  3. http://127.0.0.1:8082/img/100x100/kth.jpg