codesoap / bimg-rest

Go image scaling microservice example with bimg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go Image Scaling Microservice Example with bimg

Example implementation of a REST microservice based on bimg, a very fast image processing library which uses native library libvips via C bindings.

Build & Launch

Besides Go 1.16, libvips needs to be installed separately. bimg apparently works with libvips 8.3, but recommends 8.8+.

Locally

Follow installation instructions for libvips, e.g.

$ apt install libvips

Run the application at port 8080:

$ cd src
$ go run .

With Docker

$ docker build --pull --rm -t bimg-rest-example:latest .
$ docker run --rm -it  -p 8080:8080/tcp bimg-rest-example:latest

With docker-compose

$ docker-compose up

Usage

Send a multipart/form-data request with a single file named image to the /scale endpoint. Width and height of the target image is set via the URL query parameters width and height respectively. Optionally, image output format can be specified (jpeg, png, gif, webp, heif, or avif)

$ curl -F image=@/path/to/in.png -o /path/to/out.png http://localhost:8080/scale?width=200&height=200&format=png

Alternatively, there is also test.html with HTML form and input. While experimenting, just edit the form action URL.

See Also

About

Go image scaling microservice example with bimg

License:MIT License


Languages

Language:Go 78.6%Language:Dockerfile 13.0%Language:HTML 8.3%