HTML5 canvas+ native JavaScript real-time Get text box content draw picture watermark

Source: Internet
Author: User

Recently, a customer asked to add text watermark effect on the webpage picture, and the content is obtained from the text input box of the current webpage in real time, studied a half-day, in the net also refer to a lot of friends of the method, plus the garden enthusiastic good buddies help finally realized, first look at:

The code is as follows:

1 <!DOCTYPE HTML>                                                                        2 <Head>3     <MetaCharSet= "UTF-8">4     <title>Drawing by input text</title>                                                                            5 </Head>6 7 <Body>8 <CanvasID= "MyCanvas"width= "+"Height= "$" >9 Your Browser does not support the HTML5 canvas tag.Ten </Canvas> One  A <Script>                                                     -      - window.onload= function () { the         -         varimg= NewImage (); - img.src= './img/demo.jpg'; - Img.onload= function () { +             // -             varCanvas=document.getElementById ("MyCanvas"); +             varCTX=Canvas.getcontext ("2d");  A             // at ctx.drawimage (IMG,0, 0); -  - Ctx.font= "80px Microsoft Yahei"; - Ctx.fillstyle= "Rgba (252,255,255,0.8)"; -             //the contents of the text box are added to the picture area. - document.getElementById ("btn"). onclick= function () { in Ctx.filltext (document.getElementById ("text"). Value, -,  $); -             //document.getElementById ("text"). Value = ""//You can choose whether to empty the contents of the input box to     } +     } -     }     the </Script> *  $ <BR> Panax Notoginseng <inputtype= "text"ID= "text"value="" /> - <inputtype= "button"ID= "BTN"value= "Submit"Click= "Draw" /> the                                                                          + </Body> A </HTML>

HTML5 canvas+ native JavaScript real-time Get text box content draw picture watermark

@ Rizhao star qq:469135789 reprint please indicate the source, retain the copyright information.

HTML5 canvas+ native JavaScript real-time Get text box content draw picture watermark

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.