feat: watermark默认样式优化

This commit is contained in:
ocean-gao 2022-04-19 19:55:29 +08:00
parent 2ca3951c3f
commit 5fa7bb0af4

View File

@ -37,12 +37,12 @@ export function createWatermark({
height = '300px', height = '300px',
textAlign = 'center', textAlign = 'center',
textBaseline = 'middle', textBaseline = 'middle',
font = '16px Microsoft Yahei', font = '14px Microsoft Yahei',
fillStyle = 'rgba(184, 184, 184, 0.2)', fillStyle = 'rgba(184, 184, 184, 0.3)',
content = '请勿外传', content = '请勿外传',
rotate = '45', rotate = '25',
zIndex = 99999, zIndex = 99999,
timestamp = 'YYYY-MM-DD hh:mm' timestamp = 'YYYY-MM-DD HH:mm'
} = {}) { } = {}) {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
if (WATERMARK_DISABLED) { if (WATERMARK_DISABLED) {
@ -73,10 +73,15 @@ export function createWatermark({
ctx.translate(parseFloat(width) / 2, parseFloat(height) / 2); ctx.translate(parseFloat(width) / 2, parseFloat(height) / 2);
ctx.rotate(-(Math.PI / 180) * rotate); ctx.rotate(-(Math.PI / 180) * rotate);
ctx.fillText( ctx.fillText(
`${content}${timestamp ? ` ${timeFormat(new Date(), timestamp)}` : ''}`, `${content}`,
0, 0,
0 0
); );
timestamp && ctx.fillText(
`${timeFormat(new Date(), timestamp)}`,
0,
20
);
let __wm = document.querySelector('.__wm'); let __wm = document.querySelector('.__wm');
const watermarkDiv = __wm || document.createElement('div'); const watermarkDiv = __wm || document.createElement('div');