-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Docker Image CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
push_to_registry: | ||
name: Push Docker image to Docker Hub | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/[email protected] | ||
with: | ||
images: codeinchq/watermarker | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
target: watermarker-prod | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
/node_modules |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#################################################################################################### | ||
# WATERMARKER | ||
#################################################################################################### | ||
FROM --platform=$TARGETPLATFORM node:21-alpine AS watermarker | ||
|
||
ENV PORT=3000 | ||
ENV NODE_ENV=production | ||
WORKDIR /app | ||
|
||
|
||
#################################################################################################### | ||
# WATERMARKER dev | ||
#################################################################################################### | ||
FROM watermarker AS watermarker-dev | ||
|
||
ENV NODE_ENV=development | ||
RUN npm install --global nodemon | ||
|
||
EXPOSE $PORT | ||
ENTRYPOINT ["nodemon", "main.mjs"] | ||
|
||
|
||
#################################################################################################### | ||
# WATERMARKER prod | ||
#################################################################################################### | ||
FROM watermarker AS watermarker-prod | ||
|
||
COPY main.mjs /app/ | ||
COPY package.json /app/ | ||
COPY package-lock.json /app/ | ||
RUN mkdir -p /app/temp | ||
RUN npm install --omit=dev | ||
|
||
EXPOSE $PORT | ||
ENTRYPOINT ["node", "main.mjs"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,7 @@ | ||
MIT License | ||
Copyright 2024 Code Inc. / Joan Fabrégat <[email protected]> | ||
|
||
Copyright (c) 2024 Joan Fabrégat | ||
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: | ||
|
||
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: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
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. | ||
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,61 @@ | ||
# watermarker | ||
A containerized REST API for applying watermarks to images and PDF documents | ||
|
||
[![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) | ||
|
||
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. | ||
|
||
The image is available on [Docker Hub](https://hub.docker.com/r/codeinchq/watermarker) under the name `codeinchq/watermarker`. | ||
|
||
## Configuration | ||
|
||
By default, the container listens on port 3000. The port is configurable using the `PORT` environment variable. | ||
|
||
## Usage | ||
|
||
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: | ||
* `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. | ||
* `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`. | ||
* `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`. | ||
* `format`: The format of the output image. The value must be one of `jpg`, `png`, `gif`. The default value is `png`. | ||
* `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`. | ||
* `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}`). | ||
|
||
### Example | ||
|
||
#### Step 1: run the container using Docker | ||
|
||
```bash | ||
docker run -p "3000:3000" codeinchq/watermarker | ||
``` | ||
|
||
#### Step 2: apply the watermark to an image | ||
|
||
A simple scenario to apply a watermark to an image using `curl`: | ||
```bash | ||
curl -X POST -F "image=@/path/po/image.png" -F "watermark=@/path/to/watermark.png" http://localhost:3000/apply -o watermarked.png | ||
``` | ||
|
||
A more complex scenario with additional parameters: | ||
```bash | ||
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 | ||
``` | ||
|
||
## Client | ||
|
||
A PHP 8 client is available at on [GitHub](https://github.com/codeinchq/watermarker-php-client) | ||
and [Packagist](https://packagist.org/packages/codeinc/watermarker-client). | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see | ||
the [LICENSE](https://github.com/codeinchq/watermarker?tab=MIT-1-ov-file) file for details. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
services: | ||
watermarker-dev: | ||
image: watermarker-dev | ||
build: | ||
context: . | ||
target: watermarker-dev | ||
platforms: | ||
#- linux/amd64 | ||
- linux/arm64 | ||
volumes: | ||
- ./:/app/ | ||
ports: | ||
- "3000:3000" | ||
tty: true |