Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does html5 draw posters

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to draw posters in html5". In daily operation, I believe many people have doubts about how to draw posters in html5. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to draw posters in html5". Next, please follow the editor to study!

Don't talk too much nonsense, put on the code.

The dom node is very simple. Just generate a canvas tag and write some attributes at will.

Var canvas = document.getElementById ("myCanvas"); / / get canvas node function imageToCanvas (canvas,url1,url2,code) {/ / input canvas node background image url1 avatar url2 QR code code var ctx = canvas.getContext ("2d"); var img1 = new Image (); img1.src = url1 / / without the previous explanation, generate an image img1.onload = function () {ctx.drawImage (img1,0,0); / / when the image is loaded and assigned to the canvas starting from 0. Var img2 = new Image (); img2.src = url2; img2.onload = function () {ctx.save (); / / Save the current canvas state ctx.arc (374,134,44,0,2 * Math.PI) / / cut the square avatar into a circle / / cut the circle ctx.clip () from the canvas; / / cut the ctx.drawImage (img2, 330,90,88, 88); / / put the img2 in the size 88 ctx.restore () at 33090 coordinates. / / release canvas status ctx.font= "28px Arial"; ctx.textAlign= "center"; ctx.fillStyle ='# FFFFFF'; / / before setting the text property to center ctx.fillText ("what's your name", 375220) / / text here is written dead. In practice, one more parameter is ok var img3 = new Image (); img3.src = code; img3.onload = function () {ctx.drawImage (img3136554478478); / / same plus image var imgCode = convertCanvasToImage (canvas) / / convert the picture to base64 console.log (imgCode.getAttribute ('src'))} imageToCanvas (canvas, "1.png",' 3.jpeg)); / / initialize function convertCanvasToImage (canvas) {var image = new Image (); image.src = canvas.toDataURL ("image/png"); / / convert canvas to img return image;}

So you can get a base64 and then you can use it.

At this point, the study on "how to draw posters in html5" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report