{"id":7568,"date":"2014-05-05T05:02:56","date_gmt":"2014-05-04T19:02:56","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=7568"},"modified":"2014-05-05T05:02:56","modified_gmt":"2014-05-04T19:02:56","slug":"htmljavascript-canvas-image-copy-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/htmljavascript-canvas-image-copy-tutorial\/","title":{"rendered":"HTML\/Javascript Canvas Image Copy Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/surd_withimagecopy_chalkboard.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"HTML\/Javascript Canvas Image Copy Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/surd_withimagecopy_chalkboard.jpg\" title=\"HTML\/Javascript Canvas Image Copy Tutorial\"  \/><\/a><p class=\"wp-caption-text\">HTML\/Javascript Canvas Image Copy Tutorial<\/p><\/div>\n<p>The Canvas HTML element tag can be used as the container to draw graphics on the fly usually via the use of Javascript functions for rendering and event management.<\/p>\n<p>In today&#8217;s tutorial we add to the functionality of the previous <a target=_blank title='HTML\/Javascript Canvas Surds Game Tutorial' href='#hjcsgt'>HTML\/Javascript Canvas Surds Game Tutorial<\/a>, as shown below, where we draw an image on the canvas via drawImage() method, by, today, allowing the user to copy (via the <a target=_blank href='https:\/\/developer.mozilla.org\/en\/docs\/Web\/API\/HTMLCanvasElement#Example.3A_Getting_the_data-url_for_a_canvas' title='Canvas toDataURL() method ideas ... thanks'>toDataURL()<\/a> method) the Canvas&#8217;s image ready to email (as the body of the email) to a fellow user collaborating or sharing the game with you.   In the case of this tutorial that image contributes to the user answering some mathematics questions regarding <a target=_blank title='Surds (in maths)' href='http:\/\/www.mathsisfun.com\/surds.html'>Surds<\/a> on a simulated <i>&#8220;chalkboard&#8221;<\/i>.<\/p>\n<p>You&#8217;ll notice we don&#8217;t mention PHP as a server-side language here, so you will have to have less automation of this process (because Javascript client-side cannot write to the server file system) &#8230; so you use the browser&#8217;s (right-click) Copy Image functionality as a way to Paste the image data into the body of your email.<\/a><\/p>\n<p>You may want to read more at <a target=_blank title='HTML Canvas Reference' href='http:\/\/www.w3schools.com\/tags\/ref_canvas.asp'>HTML Canvas Reference<\/a> as a generic reference, or here, at the tutorial <a target=_blank title='javascript - How do I add a simple onClick event handler to a canvas element? - Stack Overflow' href='http:\/\/stackoverflow.com\/questions\/9880279\/how-do-i-add-a-simple-onclick-event-handler-to-a-canvas-element'>javascript &#8211; How do I add a simple onClick event handler to a canvas element? &#8211; Stack Overflow<\/a>.<\/p>\n<p>As you can imagine, this HTML canvas element, new to HTML5, can be very useful for some practical client-side web functionality.<\/p>\n<p>Link to some downloadable HTML programming code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/surd_withimagecopy_chalkboard.html_GETME' title='surd_withimagecopy_chalkboard.html'>surd_withimagecopy_chalkboard.html<\/a>\n<\/p>\n<p>You&#8217;ll notice heavy use of the Javascript <a target=_blank title='Javascript Math.random() information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/jsref_random.asp'>Math.random()<\/a> function.<\/p>\n<p>We hope you enjoy this tutorial as a <a target=_blank title='Canvas HTML element live run tutorial'  href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/surd_withimagecopy_chalkboard.html\">live run<\/a>.<\/p>\n<p>Almost finally, need to thank a great link for coding ideas with this tutorial, here, at this <a target=_blank href='http:\/\/stackoverflow.com\/questions\/10673122\/how-to-save-canvas-as-an-image-with-canvas-todataurl' title='Canvas Image Copy coding ideas ... thanks'>link<\/a>.<\/p>\n<p>Finally, have a look at the differences in code that arrived at this extra functionality by examining <a target=_blank title='surd_withimagecopy_chalkboard.html' href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/surd_chalkboard.html-GETME\">surd_withimagecopy_chalkboard.html<\/a> link.<\/p>\n<p>Yes &#8230; you&#8217;ve reached the end &#8230; hope you have a good time practising your mathematics knowledge of Surds (there is advice, if you want to learn &#8230; you can get it when you give an incorrect answer)!   Try the emailing, via image copying, functionality, as well, if you like.<\/p>\n<hr \/>\n<p id='hjcsgt'>Previous <a target=_blank title='HTML\/Javascript Canvas Surds Game Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=7264'>HTML\/Javascript Canvas Surds Game Tutorial<\/a> of interest is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/surd_chalkboard.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"HTML\/Javascript Canvas Chalkboard Game Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/surd_chalkboard.jpg\" title=\"HTML\/Javascript Canvas Surds Game Tutorial\"  \/><\/a><p class=\"wp-caption-text\">HTML\/Javascript Canvas Surds Game Tutorial<\/p><\/div>\n<p>The Canvas HTML element tag can be used as the container to draw graphics on the fly usually via the use of Javascript functions for rendering and event management.<\/p>\n<p>In today&#8217;s tutorial we touch on the functionality to draw an image on the canvas via drawImage() method.   In the case of this tutorial that image contributes to the user answering some mathematics questions regarding <a target=_blank title='Surds (in maths)' href='http:\/\/www.mathsisfun.com\/surds.html'>Surds<\/a> on a simulated <i>&#8220;chalkboard&#8221;<\/i>.<\/p>\n<p>You may want to read more at <a target=_blank title='HTML Canvas Reference' href='http:\/\/www.w3schools.com\/tags\/ref_canvas.asp'>HTML Canvas Reference<\/a> as a generic reference, or here, at the tutorial <a target=_blank title='javascript - How do I add a simple onClick event handler to a canvas element? - Stack Overflow' href='http:\/\/stackoverflow.com\/questions\/9880279\/how-do-i-add-a-simple-onclick-event-handler-to-a-canvas-element'>javascript &#8211; How do I add a simple onClick event handler to a canvas element? &#8211; Stack Overflow<\/a>.<\/p>\n<p>As you can imagine, this HTML canvas element, new to HTML5, can be very useful for some practical client-side web functionality.<\/p>\n<p>Link to some downloadable HTML programming code &#8230; rename to <a target=_blank href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/surd_chalkboard.html_GETME' title='surd_chalkboard.html'>surd_chalkboard.html<\/a>\n<\/p>\n<p>You&#8217;ll notice heavy use of the Javascript <a target=_blank title='Javascript Math.random() information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/jsref_random.asp'>Math.random()<\/a> function.<\/p>\n<p>We hope you enjoy this tutorial as a <a target=_blank title='Canvas HTML element live run tutorial'  href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/Canvas\/Game\/Chalkboard\/surd_chalkboard.html\">live run<\/a>.<\/p>\n<p>Yes &#8230; you&#8217;ve reached the end &#8230; hope you have a good time practising your mathematics knowledge of Surds (there is advice, if you want to learn &#8230; you can get it when you give an incorrect answer)!<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d7264' onclick='var dv=document.getElementById(\"d7264\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=canvas\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d7264' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d7568' onclick='var dv=document.getElementById(\"d7568\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=canvas\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d7568' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The Canvas HTML element tag can be used as the container to draw graphics on the fly usually via the use of Javascript functions for rendering and event management. In today&#8217;s tutorial we add to the functionality of the previous &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/htmljavascript-canvas-image-copy-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,15,17,37],"tags":[184,281,380,477,503,576,652,752,997,1319],"class_list":["post-7568","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-games","category-gui","category-tutorials","tag-canvas","tag-css","tag-email","tag-games-2","tag-gmail","tag-html","tag-javascript","tag-mathematics","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/7568"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=7568"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/7568\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=7568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=7568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=7568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}