首页 > 其他 > 详细

图片 文字合成

时间:2019-10-25 11:18:49      阅读:72      评论:0      收藏:0      [点我收藏+]

//图片文字合成
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);
};
}

图片 文字合成

原文:https://www.cnblogs.com/namehou/p/11736349.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!