@@ -55,7 +55,7 @@ export class WatermarkAction extends BaseImageAction {
55
55
}
56
56
57
57
public validate ( params : string [ ] ) : ReadOnly < WatermarkOpts > {
58
- let opt : WatermarkOpts = {
58
+ const opt : WatermarkOpts = {
59
59
text : '' ,
60
60
t : 100 ,
61
61
g : 'southeast' ,
@@ -187,7 +187,7 @@ export class WatermarkAction extends BaseImageAction {
187
187
188
188
async textWaterMark ( ctx : IImageContext , opt : WatermarkOpts ) : Promise < void > {
189
189
const textOpt = this . calculateTextSize ( opt . text , opt . size ) ;
190
- const svg = this . textSvgStr ( opt , textOpt ) ;
190
+ const svg = this . textSvgStr ( opt , textOpt , true , opt . shadow / 100 ) ;
191
191
const svgBytes = Buffer . from ( svg ) ;
192
192
const metadata = await ctx . image . metadata ( ) ;
193
193
if ( 0 < opt . rotate ) {
@@ -265,7 +265,7 @@ export class WatermarkAction extends BaseImageAction {
265
265
async mixedWaterMark ( ctx : IImageContext , opt : WatermarkOpts ) : Promise < void > {
266
266
const bs = ctx . bufferStore ;
267
267
const textOpt = this . calculateTextSize ( opt . text , opt . size ) ;
268
- const svg = this . textSvgStr ( opt , textOpt , false ) ;
268
+ const svg = this . textSvgStr ( opt , textOpt , false , opt . shadow / 100 ) ;
269
269
const svgBytes = Buffer . from ( svg ) ;
270
270
271
271
const watermarkImgBuffer = ( await bs . get ( opt . image ) ) . buffer ;
@@ -342,13 +342,16 @@ export class WatermarkAction extends BaseImageAction {
342
342
height : Math . round ( fontSize * 1.2 ) ,
343
343
} ;
344
344
}
345
- textSvgStr ( opt : WatermarkOpts , textOpt : WatermarkTextOpts , applyOpacity : boolean = true ) : string {
345
+ textSvgStr ( opt : WatermarkOpts , textOpt : WatermarkTextOpts , applyOpacity : boolean = true , shadow : number = 0 ) : string {
346
346
const xOffset = Math . round ( textOpt . width / 2 ) ;
347
347
const yOffset = Math . round ( textOpt . height * 0.8 ) ;
348
348
const color = `#${ opt . color } ` ;
349
349
const opacity = applyOpacity ? opt . t / 100 : 1 ;
350
+ // https://gitlab.gnome.org/GNOME/librsvg/-/blob/main/FEATURES.md
351
+ // https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/529
352
+ // https://github.com/lovell/sharp/issues/1490#issuecomment-1162760143
350
353
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${ textOpt . width } ${ textOpt . height } " text-anchor="middle">
351
- <text font-size=' ${ opt . size } ' x="${ xOffset } " y="${ yOffset } " fill="${ color } " opacity="${ opacity } " font-family="${ opt . type } ">${ opt . text } </text>
354
+ <text filter="drop-shadow(rgba(0,0,0, ${ shadow } ) 2px 0px 2px)" font-size=" ${ opt . size } " x="${ xOffset } " y="${ yOffset } " fill="${ color } " opacity="${ opacity } " font-family="${ opt . type } ">${ opt . text } </text>
352
355
</svg>` ;
353
356
return svg ;
354
357
}
0 commit comments