Add images on canvas using Canvas
First create a dom in template
<div style="display:none"> <img ref="conf0" src="../../assets/image/"> </div>
Then draw the code and write it
// Get Canvas drawinglet myCanvas = this.$ var ctx = ('2d') // Add pictures in Canvas Canvasvar img = this.$refs.conf0 = () => { (img, 0, 0) }
Use canvas to add text to the image
<template> <div> <img src="" alt="" style="width:278px;height:298px"> <canvas width="278" height="298"> </canvas> </div> </template> <script> export default { data () { return { } }, mounted () { ('123#') }, methods: { newImage (text) { // Generate pictures var imageBox = ("newimage") var canvas = ("canvas") var cxt = ("2d") var img = new Image() = require('@/assets/') // The image is loaded before processing can be done = () => { // Drawing (the canvas and pictures are the same width and height here) (img, 0, 0) // Set the font size = "36px Microsoft YaHei" // After changing the font size, you must reset the alignment, otherwise it will be troublesome to center. Set the vertical alignment of text = 'middle' = 'center' // The position to the left var left = / 2 // The position from the top (picture height - the distance from the bottom of the picture) var top = * 0.14 // Text color = "#ffffff" // The position of the text in the canvas (text, left, top) = ("image/jpg") // = 1 } }, } } </script>
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.