Images converting and storing service. Allow to crop, resize, rotate images on-fly.
Has modular architecture with different storage and caches available.
Just use this image in your docker-compose:
version: '3'
services:
web:
image: hypnocapybara/images-server
volumes:
- ./uploads:/app/uploads
ports:
- "5000:80"
And it goes to 5000 port
Has following operations:
-
POST /upload
withfile
parameter. Will save provided file in chosen storage and on success return:{ "hash": "<hash>", "status": "success" }
-
GET /image/<hash>
will return saved image.Also possible to perform operations pipeline:
/image/<hash>/resize/x200/crop/e200x200
-
Crop:
GET /image/<hash>/crop/<gravity><width>x<height>
, ex:c200x200
Possible gravity values:
- 'nw' - 'north_west',
- 'n' - 'north',
- 'ne' - 'north_east',
- 'w' - 'west',
- 'c' - 'center',
- 'e' - 'east',
- 'sw' - 'south_west',
- 's' - 'south',
- 'se' - 'south_east'
-
Resize:
GET /image/<hash>/resize/<geometry>
ex:200x
Geometry examples:
200x200
- specified sizex100
- height = 100px, width calculated automatically300x200>
if larger than 300x200, fit within box, preserving aspect ratio
Other examples at ImageMagic documentation: https://www.imagemagick.org/script/command-line-processing.php#geometry
-
Combined:
GET /image/<hash>/resize/400x400/crop/n100x100
-
External images:
GET /external?url=<external_image_url>&operations=<operations>
Possible
<operations>
are listed above<external_image_url>
must contain valid external imageDefault cache will be used to store the processed image. If you want to update the image (for example, it was changed, but URL is just the same), you may add
reset_cache=1
GET param to the URL, ex:GET /external?url=<external_image_url>&operations=<operations>&reset_cache=1
But pay attention, that with this param, the image will be always downloaded, that may slow down the request.
-
Delete image:
DELETE /image/<hash>
response with code 200:
{ "status": "success" }
or with code = 404, if image is not exists:
{ "status": "error", "message": "file not found" }
TODO-list:
- Make core - upload, view, basic transforms
- Implement filesystem cache
- Dockerize it!
- Publish docker image
- New URL for images from external sources
-
Redis, (memcached?) cachesBad idea. Just use NGINX as cache - Environment setup: choose cache, storage, disable upload, etc...
- Delete images
- Tests
- Smart crop
Optional:
- Images filters