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.
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
You need to install ImageMagick first.
sudo port install ImageMagick
brew install imagemagick
sudo apt-get install libmagickwand-dev
go get github.com/vanng822/imgscale/imagick
go get github.com/vanng822/imgscale/imgscale
// r2router: github.com/vanng822/r2router
app := r2router.NewSeeforRouter()
handler := imgscale.Configure("./config/formats.json")
defer handler.Cleanup()
app.WrapHandler(handler.ServeHTTP)
go http.ListenAndServe(fmt.Sprintf("%s:%d", "127.0.0.1", 8080), app)
// Negroni
app := negroni.New()
handler := imgscale.Configure("./config/formats.json")
// Free C pointers and terminate MagickWand environment
defer handler.Cleanup()
n.UseHandler(handler)
go http.ListenAndServe(fmt.Sprintf("%s:%d", "127.0.0.1", 8080), app)
// Martini
app := martini.Classic()
handler := imgscale.Configure("./config/formats.json")
defer handler.Cleanup()
app.Use(handler.ServeHTTP)
go http.ListenAndServe(fmt.Sprintf("%s:%d", "127.0.0.1", 8080), app)
// http.Handler
handler := imgscale.Configure("./config/formats.json")
defer handler.Cleanup()
http.Handle("/", handler)
http.ListenAndServe(fmt.Sprintf("%s:%d", "127.0.0.1", 8080), nil)
git clone https://github.com/vanng822/imgscale.git
go get github.com/gographics/imagick/imagick
go get github.com/vanng822/imgscale/imgscale
go get github.com/go-martini/martini
go get github.com/codegangsta/negroni
go run example/all.go
http://127.0.0.1:8080/img/100x100/kth.jpg
http://127.0.0.1:8081/img/100x100/http://127.0.0.1:8080/img/original/kth.jpg
http://127.0.0.1:8082/img/100x100/kth.jpg