@@ -19,6 +19,7 @@ export interface WatermarkOpts extends IActionOpts {
19
19
order : number ; // 图文混排中,文字图片的先后顺序
20
20
interval : number ; // 图文混排中,图片和文字间隔
21
21
align : number ; // 图文混排中,图片和文字对其方式
22
+ type : string ; // 字体
22
23
23
24
}
24
25
@@ -47,7 +48,7 @@ export class WatermarkAction implements IImageAction {
47
48
public readonly name : string = 'watermark' ;
48
49
49
50
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' } ;
51
52
52
53
for ( const param of params ) {
53
54
if ( ( this . name === param ) || ( ! param ) ) {
@@ -124,6 +125,11 @@ export class WatermarkAction implements IImageAction {
124
125
125
126
} else if ( k === 'color' ) {
126
127
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
+ }
127
133
} else {
128
134
throw new InvalidArgument ( `Unkown param: "${ k } "` ) ;
129
135
}
@@ -310,7 +316,7 @@ export class WatermarkAction implements IImageAction {
310
316
const color = `#${ opt . color } ` ;
311
317
const opacity = applyOpacity ? opt . t / 100 : 1 ;
312
318
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>
314
320
</svg>` ;
315
321
return svg ;
316
322
}
0 commit comments