//图片文字合成
synthesis(type, text, myId) {
let imgURL;
switch (type) {
case '1.html' :
imgURL = 'static/images/1.png';
break;
case '2.html' :
imgURL = 'static/images/2.png';
break;
case '3.html' :
imgURL = 'static/images/3.png';
break;
default:
imgURL = 'static/images/4.png';
break;
}
let img;
document.getElementById(myId).height = 0;
document.getElementById(myId).height = 100;
var mainCtx = document.getElementById(myId).getContext("2d");
// 创建一个待合成图片
var starImg = new Image();
starImg.src = imgURL;
starImg.onload = function () {
//图片绘制
mainCtx.drawImage(starImg, 31, 18, 38, 32);
//文本,图片合成
mainCtx.font = "normal 500 14px Arial";
mainCtx.fillStyle = "#073061";
mainCtx.textAlign = "center";
mainCtx.fillText(text, 50, 70, 80);
//导出合成图片
var mycanvas = document.getElementById(myId);
img = mycanvas.toDataURL("image/jpeg", 1.0);
};
}