Skip to content

Commit 4811a51

Browse files
committed
first version 👍
1 parent 714579d commit 4811a51

20 files changed

+2097
-19
lines changed

.github/workflows/docker-image.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
tags:
8+
- 'v*'
9+
10+
jobs:
11+
push_to_registry:
12+
name: Push Docker image to Docker Hub
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Check out the repo
16+
uses: actions/checkout@v4
17+
18+
- name: Set up QEMU
19+
uses: docker/setup-qemu-action@v3
20+
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
24+
- name: Log in to Docker Hub
25+
uses: docker/login-action@v3
26+
with:
27+
username: ${{ secrets.DOCKERHUB_USERNAME }}
28+
password: ${{ secrets.DOCKERHUB_TOKEN }}
29+
30+
- name: Extract metadata (tags, labels) for Docker
31+
id: meta
32+
uses: docker/[email protected]
33+
with:
34+
images: codeinchq/watermarker
35+
36+
- name: Build and push Docker image
37+
uses: docker/build-push-action@v5
38+
with:
39+
context: .
40+
platforms: linux/amd64,linux/arm64
41+
target: watermarker-prod
42+
push: true
43+
tags: ${{ steps.meta.outputs.tags }}
44+
labels: ${{ steps.meta.outputs.labels }}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
/node_modules

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jsLibraryMappings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/watermarker.iml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
####################################################################################################
2+
# WATERMARKER
3+
####################################################################################################
4+
FROM --platform=$TARGETPLATFORM node:21-alpine AS watermarker
5+
6+
ENV PORT=3000
7+
ENV NODE_ENV=production
8+
WORKDIR /app
9+
10+
11+
####################################################################################################
12+
# WATERMARKER dev
13+
####################################################################################################
14+
FROM watermarker AS watermarker-dev
15+
16+
ENV NODE_ENV=development
17+
RUN npm install --global nodemon
18+
19+
EXPOSE $PORT
20+
ENTRYPOINT ["nodemon", "main.mjs"]
21+
22+
23+
####################################################################################################
24+
# WATERMARKER prod
25+
####################################################################################################
26+
FROM watermarker AS watermarker-prod
27+
28+
COPY main.mjs /app/
29+
COPY package.json /app/
30+
COPY package-lock.json /app/
31+
RUN mkdir -p /app/temp
32+
RUN npm install --omit=dev
33+
34+
EXPOSE $PORT
35+
ENTRYPOINT ["node", "main.mjs"]

LICENSE

+4-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
1-
MIT License
1+
Copyright 2024 Code Inc. / Joan Fabrégat <[email protected]>
22

3-
Copyright (c) 2024 Joan Fabrégat
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
116

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
14-
15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+60-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
11
# watermarker
2-
A containerized REST API for applying watermarks to images and PDF documents
2+
3+
[![Docker Image CI](https://github.com/codeinchq/watermarker/actions/workflows/docker-image.yml/badge.svg)](https://github.com/codeinchq/watermarker/actions/workflows/docker-image.yml)
4+
5+
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](https://www.npmjs.com/package/jimp) library to process the images.
6+
7+
The image is available on [Docker Hub](https://hub.docker.com/r/codeinchq/watermarker) under the name `codeinchq/watermarker`.
8+
9+
## Configuration
10+
11+
By default, the container listens on port 3000. The port is configurable using the `PORT` environment variable.
12+
13+
## Usage
14+
15+
All requests must by send in POST to the `/apply` endpoint with a `multipart/form-data` content type. The request must
16+
contain two files:
17+
* `image`: The image to apply the watermark to.
18+
* `watermark`: The watermark to apply to the image.
19+
20+
Additional parameters can be sent to customize the conversion process:
21+
* `ratio`: The ratio of the watermark to the image. The value must be a float between 0 and 1. The default value is 0.5.
22+
* `position`: The position of the watermark. The value must be one of `center`, `top-left`, `top`, `top-right`, `left`, `right`, `bottom-left`, `bottom`, `bottom-right`. The default value is `center`.
23+
* `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 is `center`.
24+
* `format`: The format of the output image. The value must be one of `jpg`, `png`, `gif`. The default value is `png`.
25+
* `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 is `gif` or `png`.
26+
* `blur`: The blur radius of background behind the watermark. The value must be an integer. The default value is 0.
27+
* `opacity`: The opacity of the watermark. The value must be an integer between 0 and 100. The default value is 100.
28+
29+
The server returns `200` if the conversion was successful and the images are available in the response body. In case of
30+
error, the server returns a `400` status code with a JSON object containing the error message (
31+
format: `{error: string}`).
32+
33+
### Example
34+
35+
#### Step 1: run the container using Docker
36+
37+
```bash
38+
docker run -p "3000:3000" codeinchq/watermarker
39+
```
40+
41+
#### Step 2: apply the watermark to an image
42+
43+
A simple scenario to apply a watermark to an image using `curl`:
44+
```bash
45+
curl -X POST -F "image=@/path/po/image.png" -F "watermark=@/path/to/watermark.png" http://localhost:3000/apply -o watermarked.png
46+
```
47+
48+
A more complex scenario with additional parameters:
49+
```bash
50+
curl -X POST -F "image=@/path/po/image.png" -F "watermark=@/path/to/watermark.png" http://localhost:3000/apply -F "blur=3" -F "ratio=1" -F "format=jpg" -F "quality=100" -o test-watermarked.jpg
51+
```
52+
53+
## Client
54+
55+
A PHP 8 client is available at on [GitHub](https://github.com/codeinchq/watermarker-php-client)
56+
and [Packagist](https://packagist.org/packages/codeinc/watermarker-client).
57+
58+
## License
59+
60+
This project is licensed under the MIT License - see
61+
the [LICENSE](https://github.com/codeinchq/watermarker?tab=MIT-1-ov-file) file for details.

docker-compose.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
services:
2+
watermarker-dev:
3+
image: watermarker-dev
4+
build:
5+
context: .
6+
target: watermarker-dev
7+
platforms:
8+
#- linux/amd64
9+
- linux/arm64
10+
volumes:
11+
- ./:/app/
12+
ports:
13+
- "3000:3000"
14+
tty: true

0 commit comments

Comments
 (0)