微信小程序成海报

# ios 设置字体(sans-serif)画布正常画字体
ctx.font = "bold small-caps 36px sans-serif";
ctx.textAlign = "center";
ctx.fillStyle = "#666";
ctx.fillText("刮奖区",c1.width/2,c1.height/2+12);
  // 生成海报
  poster(codeurl = 'https://ysch-1318476842.cos.ap-guangzhou.myqcloud.com/ccs/gjzyjgs_v2.jpg') {
    const query = wx.createSelectorQuery()
    query.select('#canvas')
      .fields({
        node: true,
        size: true
      })
      .exec((res) => {
        const canvas = res[0].node
        const dpr = wx.getSystemInfoSync().pixelRatio;
        canvas.width = res[0].width * dpr
        canvas.height = res[0].height * dpr
        this.Acanvas = canvas;
        this.width = res[0].width * dpr;
        this.height = res[0].height * dpr;
        const ctx = canvas.getContext('2d')
        const img = canvas.createImage()
        img.onload = () => {
          ctx.drawImage(img, 0, 0, res[0].width * dpr, res[0].height * dpr)
          // 小程序码
          const img1 = canvas.createImage()
          img1.onload = () => {
            ctx.drawImage(img1, rpx2px(562.9 * dpr), rpx2px(352.8 * dpr), rpx2px(78 * dpr), rpx2px(78 * dpr))
            const img2 = canvas.createImage()
            img2.onload = () => {
              ctx.drawImage(img2, rpx2px(158 * dpr), rpx2px(76 * dpr), rpx2px(62 * dpr), rpx2px(78 * dpr))
              ctx.font = "small-caps "+8*dpr+"px sans-serif";
              ctx.textAlign = "center";
              ctx.fillStyle = "#000";
              ctx.fillText('朱海兵', rpx2px(158 * dpr), rpx2px(208 * dpr))
              ctx.fillText('男', rpx2px(288 * dpr), rpx2px(208 * dpr))
              ctx.fillText('**************', rpx2px(230 * dpr), rpx2px(248 * dpr))
              ctx.fillText('1993', rpx2px(178 * dpr), rpx2px(292 * dpr))
              ctx.fillText('03', rpx2px(230 * dpr), rpx2px(292 * dpr))
              ctx.fillText('24', rpx2px(276 * dpr), rpx2px(292 * dpr))
              ctx.fillText('GJZY00230301387586', rpx2px(246 * dpr), rpx2px(342 * dpr))
              ctx.fillText('2023年07月04日', rpx2px(226 * dpr), rpx2px(382 * dpr))
              ctx.fillText('朱海兵', rpx2px(490 * dpr), rpx2px(118 * dpr))
              ctx.fillText('朱海兵', rpx2px(568 * dpr), rpx2px(222 * dpr))
              ctx.fillText('2023', rpx2px(398 * dpr), rpx2px(419 * dpr))
              ctx.fillText('07', rpx2px(462 * dpr), rpx2px(419 * dpr))
              ctx.fillText('04', rpx2px(516 * dpr), rpx2px(419 * dpr))
              ctx.scale(dpr, dpr)
            }
            img2.src = this.data.idphotoUrl
          }
          img1.src = codeurl
        }
        img.src = codeurl
      })
  },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

web修理工

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值