This repository contains a simple containerized REST API to apply a watermark to an image. The server is written in Javascript and uses the Jimp library to process the images.
The image is available on Docker Hub under the name codeinchq/watermarker
.
By default, the container listens on port 3000. The port is configurable using the PORT
environment variable.
All requests must by send in POST to the /apply
endpoint with a multipart/form-data
content type. The request must
contain two files:
image
: The image to apply the watermark to.watermark
: The watermark to apply to the image.
Additional parameters can be sent to customize the conversion process:
size
: The size of the watermark in relation to the image in percentage. The value must be an integer. The default value is 75.position
: The position of the watermark. The value must be one ofcenter
,top-left
,top
,top-right
,left
,right
,bottom-left
,bottom
,bottom-right
. The default value iscenter
.padding
: The padding between the watermark and the edge of the image. The value must be an integer. The default value is 10. This is ignored if the position iscenter
.format
: The format of the output image. The value must be one ofjpg
,png
,gif
. The default value ispng
.quality
: The quality of the output image. The value must be an integer between 0 and 100. The default value is 100. This is ignored if the format isgif
orpng
.blur
: The blur radius of background behind the watermark. The value must be an integer. The default value is 0.opacity
: The opacity of the watermark. The value must be an integer between 0 and 100. The default value is 100.
The server returns 200
if the conversion was successful and the images are available in the response body. In case of
error, the server returns a 400
status code with a JSON object containing the error message (
format: {error: string}
).
docker run -p "3000:3000" codeinchq/watermarker
A simple scenario to apply a watermark to an image using curl
:
curl -X POST http://localhost:3000/apply -F "image=@/path/to/image.png" -F "watermark=@/path/to/watermark.png" -o watermarked.png
A more complex scenario with additional parameters:
curl -X POST http://localhost:3000/apply -F "image=@/path/to/image.png" -F "watermark=@/path/to/watermark.png" -F "blur=3" -F "size=100" -F "format=jpg" -F "quality=100" -o test-watermarked.jpg
A health check is available at the /health
endpoint. The server returns a status code of 200
if the service is healthy, along with a JSON object:
{ "status": "up" }
A PHP 8 client is available at on GitHub and Packagist.
This project is licensed under the MIT License - see the LICENSE file for details.