Skip to content

Commit 6edcc70

Browse files
committed
feat: replace decodeBlindWatermark with decode
1 parent de0b46a commit 6edcc70

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

.changeset/sour-steaks-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@watermark-design/node': patch
3+
---
4+
5+
replace **decodeBlindWatermark** with **decode**

packages/node/README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,26 @@
1414

1515
# `@watermark-design/node`
1616

17-
The utils used internally by the Watermark Design. It includes common type checking, error assertions, component types/declarations/parameters, and more.
18-
1917
## Installing
2018

2119
```bash
2220
# or pnpm or yarn
2321
npm install @watermark-design/node
2422
```
2523

24+
## Usage
25+
26+
```ts
27+
import * as watermark from '@watermark-design/node';
28+
watermark.blind
29+
.decode({
30+
url: 'https://cdn.jsdelivr.net/gh/zhensherlock/oss@main/uPic/blind-watermark-test-bxEJgQ.png',
31+
})
32+
.then((res) => {
33+
console.log(res); // image base64 after decryption
34+
});
35+
```
36+
2637
## Documentation
2738

2839
To learn more, check [its documentation](https://watermark-design.github.io/watermark/).

packages/node/src/blind.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { createCanvas, loadImage } from 'canvas';
1+
import { createCanvas, GlobalCompositeOperation, loadImage } from 'canvas';
22
import fetch from 'node-fetch';
33

44
export interface DecodeBlindWatermarkOptions {
55
url: string;
6-
fillColor: string;
7-
compositeOperation: string;
8-
mode: string;
6+
fillColor?: string;
7+
compositeOperation?: string;
8+
mode?: string;
99
}
1010

11-
export const decodeBlindWatermark = async (props: DecodeBlindWatermarkOptions) => {
11+
export const decode = async (props: DecodeBlindWatermarkOptions) => {
1212
const options = Object.assign(
1313
{
1414
url: '',
@@ -28,7 +28,7 @@ export const decodeBlindWatermark = async (props: DecodeBlindWatermarkOptions) =
2828
const canvas = createCanvas(img.width, img.height);
2929
const ctx = canvas.getContext('2d');
3030
ctx.drawImage(img, 0, 0, img.width, img.height);
31-
ctx.globalCompositeOperation = options.compositeOperation as any;
31+
ctx.globalCompositeOperation = options.compositeOperation as GlobalCompositeOperation;
3232
ctx.fillStyle = options.fillColor;
3333
ctx.fillRect(0, 0, img.width, img.height);
3434
resultImage = canvas.toDataURL();

0 commit comments

Comments
 (0)