"use strict";
const common_vendor = require("../vendor.js");
const watermark = {
  addWatermark(imagePath, watermarkTxt) {
    const ctx = common_vendor.index.createCanvasContext("myCanvas");
    common_vendor.index.getImageInfo({
      src: imagePath,
      success: (imageInfo) => {
        const { width, height } = imageInfo;
        console.log(imageInfo, "imageInfo");
        const canvasWidth = 390;
        const canvasHeight = height * canvasWidth / width;
        ctx.drawImage(imagePath, 0, 0, canvasWidth, canvasHeight);
        ctx.setFontSize(17);
        ctx.setFillStyle("#FFD415");
        ctx.rotate(-Math.PI / 4);
        ctx.fillText(watermarkTxt, -500, 400);
        ctx.fillText(watermarkTxt, -200, 200);
        ctx.fillText(watermarkTxt, -200, 300);
        ctx.fillText(watermarkTxt, -200, 400);
        ctx.fillText(watermarkTxt, -200, 600);
        ctx.fillText(watermarkTxt, -550, 800);
        ctx.draw(false, () => {
          common_vendor.index.canvasToTempFilePath({
            canvasId: "myCanvas",
            success: (res) => {
              console.log("水印图片地址:", res.tempFilePath);
              common_vendor.index.hideLoading();
              common_vendor.index.previewMedia({
                sources: [
                  {
                    url: res.tempFilePath,
                    type: "image"
                  }
                ],
                current: 0
              });
            },
            fail: (err) => {
              common_vendor.index.showToast({
                title: "获取失败",
                duration: 1e3
              });
              console.error(err);
            }
          });
        });
      }
    });
  }
};
exports.watermark = watermark;
