On the fly image cropping and resizing

Due to the wide range of screen sizes in web and mobile apps the images are often need to be resized on the fly for better user experience. But it can put unwanted load on the application server.

Its better to have a separate service do that. While there are many online services (eg. kraken.io, imgix, etc.) but I couldn't find any that I can host on my server for unlimited use.

So, I end up developing a micro-service as a docker image. It provides an http end-point that takes the original image url, desired height, width & output image format as parameters and returns the resized image.

Source code: https://github.com/shahedk/image-resizer
Docker: shahedk/image-resizer

Usage

docker pull shahedk/image-resizer:latest
docker run -p 8080:80 shahedk/image-resizer:latest

The above script will start the container at http://localhost:8080. For example, the http request to resize an image from "http://cdn.shahed.ca/default.jpg" into 100x100 pixel of PNG image would look like this:

http://localhost:8080/resize?
w=100&h=100&url=http%3A//cdn.shahed.ca/default.jpg&f=png

The service uses the sharp image libarary for resizing and supports PNG, JPEG, TIFF and WebP.

Show Comments