Skip to content

Commit

Permalink
ratio is now replaced by size in the parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
joanfabregat committed Feb 24, 2024
1 parent 11cc577 commit b87149b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contain two files:
* `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.
* `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 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`.
Expand Down Expand Up @@ -47,7 +47,7 @@ curl -X POST http://localhost:3000/apply -F "image=@/path/to/image.png" -F "wate

A more complex scenario with additional parameters:
```bash
curl -X POST http://localhost:3000/apply -F "image=@/path/to/image.png" -F "watermark=@/path/to/watermark.png" -F "blur=3" -F "ratio=1" -F "format=jpg" -F "quality=100" -o test-watermarked.jpg
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
```

## Client
Expand Down
2 changes: 1 addition & 1 deletion main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ app.post('/apply', cpUpload, async (req, res) => {
const watermarkImage = await Jimp.read(watermarkFile.path);

// calculating the dimensions of the watermark
const ratio = parseFloat(req.body.ratio ?? .75);
const ratio = (req.body.size ?? 75) / 100;
let newHeight, newWidth;
if ((mainImage.getHeight() / mainImage.getWidth()) < (watermarkImage.getHeight() / watermarkImage.getWidth())) {
newHeight = ratio * mainImage.getHeight();
Expand Down

0 comments on commit b87149b

Please sign in to comment.