Skip to content

Commit ed73982

Browse files
authored
Merge pull request #98 from dashjim/type-feature
Type feature
2 parents 14e94fb + ccf090b commit ed73982

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

source/new-image-handler/src/processor/image/watermark.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface WatermarkOpts extends IActionOpts {
1919
order: number; // 图文混排中,文字图片的先后顺序
2020
interval: number; // 图文混排中,图片和文字间隔
2121
align: number; // 图文混排中,图片和文字对其方式
22+
type: string; // 字体
2223

2324
}
2425

@@ -47,7 +48,7 @@ export class WatermarkAction implements IImageAction {
4748
public readonly name: string = 'watermark';
4849

4950
public validate(params: string[]): ReadOnly<WatermarkOpts> {
50-
let opt: WatermarkOpts = { text: '', t: 100, g: 'se', fill: false, rotate: 0, size: 40, color: '000000', image: '', auto: true, order: 0, x: undefined, y: undefined, voffset: 0, interval: 0, align: 0 };
51+
let opt: WatermarkOpts = { text: '', t: 100, g: 'se', fill: false, rotate: 0, size: 40, color: '000000', image: '', auto: true, order: 0, x: undefined, y: undefined, voffset: 0, interval: 0, align: 0, type: 'FZHei-B01'};
5152

5253
for (const param of params) {
5354
if ((this.name === param) || (!param)) {
@@ -124,6 +125,11 @@ export class WatermarkAction implements IImageAction {
124125

125126
} else if (k === 'color') {
126127
opt.color = v;
128+
} else if (k === 'type') {
129+
if (v) {
130+
const buff = Buffer.from(v, 'base64');
131+
opt.type = buff.toString('utf-8');
132+
}
127133
} else {
128134
throw new InvalidArgument(`Unkown param: "${k}"`);
129135
}
@@ -310,7 +316,7 @@ export class WatermarkAction implements IImageAction {
310316
const color = `#${opt.color}`;
311317
const opacity = applyOpacity ? opt.t / 100 : 1;
312318
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${textOpt.width} ${textOpt.height}" text-anchor="middle">
313-
<text font-size='${opt.size}' x="${xOffset}" y="${yOffset}" fill="${color}" opacity="${opacity}">${opt.text}</text>
319+
<text font-size='${opt.size}' x="${xOffset}" y="${yOffset}" fill="${color}" opacity="${opacity}" font-family="${opt.type}">${opt.text}</text>
314320
</svg>`;
315321
return svg;
316322
}

0 commit comments

Comments
 (0)