How to add some product details to the pictures of Mini Program sharing function?

problem description


such as the title. Like SUNING"s Mini Program, some product details will appear in the lower left corner of the picture after sharing. Look at it carefully, not a screenshot. How did he do it? I also want to achieve this function.

Jun.29,2022

share a function code of canvas's self-defined content in our Mini Program to share pictures

// 
  drawImg: function (e) {
    console.log('draw')
    let val = e.currentTarget.dataset.cl
    this.getClassTask(val.classId)
    this.setData({
      shareWork: val
    })
    const ctx = wx.createCanvasContext('myCanvas')
    ctx.drawImage('../../../img/teacher/share_bac.png', 0, 0, 500, 400)
    ctx.setFontSize(24)
    ctx.setFillStyle('-sharpfff')
    ctx.fillText(val.className + '', 40, 60)
    ctx.setFontSize(34)
    if (val.stepTaskNum === 0 && val.bookTaskNum === 0) {
      ctx.fillText('', 40, 125)
    } else {
      if (val.stepTaskNum > 0) {
        ctx.setFontSize(34)
        ctx.setFillStyle('-sharpfff')
        ctx.fillText('', 80, 125)
        ctx.setFillStyle('-sharpffff33')
        ctx.setFontSize(38)
        ctx.fillText(val.stepTaskNum, 40, 125)
      }
      if (val.bookTaskNum > 0) {
        ctx.setFontSize(34)
        ctx.setFillStyle('-sharpfff')
        ctx.fillText('', 80, 175)
        ctx.setFillStyle('-sharpffff33')
        ctx.setFontSize(38)
        ctx.fillText(val.bookTaskNum, 40, 175)
      }
    }
    ctx.setFontSize(22)
    ctx.setFillStyle('-sharpfff')
    ctx.fillText('>>', 40, 260)
    ctx.setFontSize(24)
    ctx.fillText(this.timeGet(new Date().getTime()), 360, 60)
    ctx.draw()
    var _this = this
    setTimeout(() => {
      wx.canvasToTempFilePath({
        x: 0,
        y: 0,
        width: 500,
        height: 400,
        destWidth: 500,
        destHeight: 400,
        canvasId: 'myCanvas',
        success: function (res) {
          _this.setData({
            path: res.tempFilePath,
            modalShare: true
          })
          console.log(res.tempFilePath)
        }
      })
    }, 300)
  }

you can draw text and pictures on a background
if you still have something you don't understand, you can trust me
~ ps: it's best to open and share the next tick after the picture drawing function is called, otherwise the picture will be empty

.
  1. draw a picture with canvas to share. two The background generates such a picture to share. In short, the thing and the picture in the lower left corner are the same picture.

Mini Program API only supports title + picture. Pictures can be drawn in custom pictures instead of default screenshots.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b42c4c-2be91.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b42c4c-2be91.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?