需求
用户可选择相应图片自定义输入文字进行组合,生成自己想要的图片
涉及功能点:
canvas
<template>
<canvas id="myCanvas" width="100" height="100"></canvas>
</template>
<script>
export default{
methods:{
fn(){
var canvas=document.getElementById('myCanvas')
var ctx=canvas.getContext('2d')
var img=new Image()
var _this=this
img.onload=function(){
ctx.drawImage(img,0,0)
ctx.font='18px Arial'
ctx.fillStyle='black'
ctx.fillText(_this.text,20,50)
_this.imgBase64=canvas.toDataURL('image/png',1)
}
img.src='data:image/png;base64,'+你的图片base64码
canvas.width=img.width
canvas.height=img.height
}
}
}
</script>