From dcf189a2ba4fcd41631bc46e5589223a79302115 Mon Sep 17 00:00:00 2001 From: ocean-gao Date: Wed, 20 Apr 2022 11:05:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20watermark=E9=BB=98=E8=AE=A4=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/reference/plugin/plugins/watermark.md | 6 +++--- packages/fes-plugin-watermark/src/runtime/core.js | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/reference/plugin/plugins/watermark.md b/docs/reference/plugin/plugins/watermark.md index 2a497348..f51b70e6 100644 --- a/docs/reference/plugin/plugins/watermark.md +++ b/docs/reference/plugin/plugins/watermark.md @@ -54,15 +54,15 @@ createWatermark({ content: '我是水印' }); ```js { container = document.body, - width = '300px', - height = '300px', + width = 300, + height = 300, textAlign = 'center', textBaseline = 'middle', fontSize = '14px', fontFamily = 'Microsoft Yahei', fillStyle = 'rgba(184, 184, 184, 0.3)', content = '请勿外传', - rotate = '25', + rotate = 25, zIndex = 99999, timestamp = 'YYYY-MM-DD HH:mm' } diff --git a/packages/fes-plugin-watermark/src/runtime/core.js b/packages/fes-plugin-watermark/src/runtime/core.js index ce8a7740..f927d255 100644 --- a/packages/fes-plugin-watermark/src/runtime/core.js +++ b/packages/fes-plugin-watermark/src/runtime/core.js @@ -33,15 +33,15 @@ function timeFormat(date, format = 'YYYY-MM-DD') { // canvas 实现 watermark export function createWatermark({ container = document.body, - width = '300px', - height = '300px', + width = 300, + height = 300, textAlign = 'center', textBaseline = 'middle', fontSize = '14px', fontFamily = 'Microsoft Yahei', fillStyle = 'rgba(184, 184, 184, 0.3)', content = '请勿外传', - rotate = '25', + rotate = 25, zIndex = 99999, timestamp = 'YYYY-MM-DD HH:mm' } = {}) { @@ -64,15 +64,15 @@ export function createWatermark({ timestamp }; const canvas = document.createElement('canvas'); - canvas.setAttribute('width', width); - canvas.setAttribute('height', height); + canvas.setAttribute('width', `${width}px`); + canvas.setAttribute('height', `${height}px`); const ctx = canvas.getContext('2d'); ctx.textAlign = textAlign; ctx.textBaseline = textBaseline; ctx.font = `${fontSize} ${fontFamily}`; ctx.fillStyle = fillStyle; - ctx.translate(parseInt(width) / 2, parseInt(height) / 2); + ctx.translate(width / 2, height / 2); ctx.rotate(-(Math.PI / 180) * rotate); ctx.fillText( `${content}`,