```php
```javascript
<template>
<view class="page">
<canvas class="canvas" :style="{width: canvasW + 'px', height: canvasH + 'px'}" canvas-id="myCanvas"></canvas>
</view>
</template>
<script>
export default {
data() {
return {
canvasW: 390,
canvasH: 750,
canvasW2: 400,
canvasH2: 400,
objInfo: {
bgImg: '../../static/jhy/diy/bg (2).png',
name: '李白',
toname: '杜甫的爸爸吧',
ziImg:'../../static/jhy/diy/1.png',
},
canvasImg:''
}
},
onLoad() {
this.btn();
},
methods: {
getImageInfo(image) {
return new Promise((req, rej) => {
uni.getImageInfo({
src: image,
success: function(res) {
req(res)
},
});
})
},
btn() {
this.poster();
},
async poster() {
var _this = this;
var info = await _this.getImageInfo(_this.objInfo.bgImg);
var info2 = await _this.getImageInfo(_this.objInfo.ziImg);
if (info.errMsg == 'getImageInfo:ok') {
uni.showToast({
icon: 'loading',
mask: true,
duration: 3000,
title: '海报绘制中',
});
var name = _this.objInfo.name;
var qrcode = info.path;
var qrcode2 = info2.path;
var toname = _this.objInfo.toname;
setTimeout(() => {
const ctx = uni.createCanvasContext('myCanvas', this);
ctx.clearRect(0, 0, _this.canvasW, _this.canvasW);
ctx.fillStyle = "#fff";
ctx.fillRect(0, 0, _this.canvasW, _this.canvasW);
var widthImg1 = (_this.canvasW - 162) / 2;
console.log('info',info)
ctx.drawImage(qrcode, 0, 0,info.width, info.height,0,0,info.width/3.2,
info.height/3.2);
ctx.drawImage(qrcode2, 0, 0, info2.width, info2.height, 60, 350, info2.width, info2.height);
ctx.font = "15px Medium";
ctx.fillStyle = '#CD0000';
var widthText1 = ctx.measureText(toname).width;
var start1 = (_this.canvasW2 - widthText1)/4 ;
ctx.fillText(toname+':', start1, 330);
ctx.font = '15px Medium';
ctx.fillStyle = '#CD0000';
var widthText2 = ctx.measureText(name).width;
var start2 = _this.canvasW2 - widthText2-100 ;
ctx.fillText(name, start2, 550)
ctx.stroke();
ctx.beginPath();
ctx.clip();
ctx.stroke();
ctx.draw(true, (ret) => {
uni.showToast({
icon: 'success',
mask: true,
title: '绘制完成',
});
uni.canvasToTempFilePath({
width: _this.canvasW,
height: _this.canvasH,
destWidth: _this.canvasW * 2,
destHeight: _this.canvasH * 2,
canvasId: 'myCanvas',
quality: 1,
complete: function(res) {
_this.canvasImg = res.tempFilePath;
console.log(_this.canvasImg)
},
})
})
}, 1000)
}
}
},
}
</script>
<style>
.page {
width: 100%;
height: 100%;
}
html,
body {
overflow: hidden;
-webkit-overflow-scrolling: touch;
}
.canvas {
position: absolute;
z-index: -1;
}
</style>