Browse Source

feat: 试卷水印调整

zhangjie 9 months ago
parent
commit
540d7dfcba
1 changed files with 7 additions and 7 deletions
  1. 7 7
      src/components/ImageWatermark.vue

+ 7 - 7
src/components/ImageWatermark.vue

@@ -66,24 +66,24 @@ export default {
       const fontSize = 100;
       ctx.font = `${fontSize}px serif`;
       ctx.fillStyle = "rgba(212,212,212,0.5)";
-
+      ctx.textAlign = "center";
+      ctx.textBaseline = "middle";
       // 获取内容的宽度
       const cInfo = ctx.measureText(this.content);
 
-      const initWH = [50, 50];
-      const spacing = [width / 3, height / 3];
-      const spaceSize = Math.max(width, height) * 1.5;
+      const spacing = [Math.max(500, width / 4), Math.max(500, height / 4)];
       const spaceWH = [cInfo.width + spacing[0], fontSize + spacing[1]];
+      const spaceSize = Math.max(width, height);
       const wCount = Math.ceil(spaceSize / spaceWH[0]);
       const hCount = Math.ceil(spaceSize / spaceWH[1]);
 
-      ctx.translate(-width / 2, height / 2);
+      ctx.translate(width / 2, height / 2);
       ctx.rotate(angle);
 
       for (let i = 0; i < wCount; i++) {
         for (let j = 0; j < hCount; j++) {
-          const x = initWH[0] + i * spaceWH[0];
-          const y = initWH[1] + j * spaceWH[1];
+          const x = -spaceSize / 2 + i * spaceWH[0];
+          const y = -spaceSize / 2 + j * spaceWH[1];
           ctx.fillText(this.content, x, y);
         }
       }