{"id":26343,"date":"2016-11-13T03:01:12","date_gmt":"2016-11-12T17:01:12","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=26343"},"modified":"2016-11-12T13:49:45","modified_gmt":"2016-11-12T03:49:45","slug":"html5-camera-api-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/html5-camera-api-primer-tutorial\/","title":{"rendered":"HTML5 Camera API Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/camera_api.html\"><img decoding=\"async\" style=\"float:left;border: 15px solid pink;\" alt=\"HTML5 Camera API Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/camera_api.jpg\" title=\"HTML5 Camera API Primer Tutorial\"   \/><\/a><p class=\"wp-caption-text\">HTML5 Camera API Primer Tutorial<\/p><\/div>\n<p>Okay, so more HTML5 awaits, and we start down the track today with some research and development regarding the Camera API, and point you towards a few unbelievably great resources that have been put before us &#8230;<\/p>\n<ul>\n<li><a target=_blank title='camera-api' href='https:\/\/github.com\/robnyman\/robnyman.github.com\/tree\/master\/camera-api'>robnyman\/robnyman.github.com<\/a> &#8230; we got onto, via &#8230;<\/li>\n<li><a target=_blank title='camera-api' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Mozilla\/B2G_OS\/API\/Camera_API\/Introduction'>Camera API introduction<\/a> &#8230; via <a target=_blank title='camera-api' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/Guide\/HTML\/HTML5'>HTML5 &#8211; Web developer guides | MDN<\/a> &#8230; and got helped with blob to data URI conversion ideas from <a target=_blank title='Convert Image to Data URI with JavaScript' href='https:\/\/davidwalsh.name\/convert-image-data-uri-javascript'>Convert Image to Data URI with JavaScript<\/a><\/li>\n<\/ul>\n<p> &#8230; and this led us to this proof of concept web application you could call <a target=_blank title='camera_api.html' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/camera_api.html_GETME'>camera_api.html<\/a> that you can try with this <a target=_blank title='Click picture' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/camera_api.html'>live run<\/a> link.  The fly in the ointment, however, is browser and platform compatibility here.  The web application &#8230;<\/p>\n<ul>\n<li>asks the user for permission to use the camera to take photographs with the device&#8217;s camera &#8230; and\/or<\/li>\n<li>asks the user to point to a local (photograph) file &#8230; and then we &#8230;<\/li>\n<li>interface either of these photographic data source and funnel it through email (client) functionality, optionally<\/li>\n<\/ul>\n<p>Browser and platform wise, that first bit of functionality above is only supported, notionally, on Firefox and Google Chrome web browsers on Android, though we also found it worked on an (iOS) iPad.  Most browsers and platforms work with the latter two features above.<\/p>\n<p>So what are the Javascript syntax highlights of making the first two of the list above &#8230; ie. the Camera API (in HTML5) &#8230; to work.  You need &#8230;<\/p>\n<ul>\n<li>capturing the data via the device camera, <b>via<\/b><br \/>\n<code><br \/>\n&lt;input onclick=\"document.getElementById('aemail').style.display='inline';\" type=\"file\" id=\"take_photograph\" <b>accept=\"image\/*\"<\/b>&gt;<br \/>\n<\/code>\n<\/li>\n<li>use of as <a target=_blank title='createObjectURL' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/URL\/createObjectURL'>createObjectURL<\/a> method <b>as per<\/b><br \/>\n<code><br \/>\nvar imgURL = window.URL.<b>createObjectURL<\/b>(file);<br \/>\n<\/code>\n<\/li>\n<li>or alternatively, the use of the <a target=_blank title='FileReader' href='https:\/\/developer.mozilla.org\/en\/docs\/Web\/API\/FileReader'>FileReader<\/a> object <b>as per<\/b><br \/>\n<code><br \/>\nvar fileReader = new <b>FileReader<\/b>();<br \/>\n<\/code>\n<\/li>\n<\/ul>\n<p>Try it out yourself to get this web application into context.<\/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='#d26343' onclick='var dv=document.getElementById(\"d26343\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/camera\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d26343' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Okay, so more HTML5 awaits, and we start down the track today with some research and development regarding the Camera API, and point you towards a few unbelievably great resources that have been put before us &#8230; robnyman\/robnyman.github.com &#8230; we &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/html5-camera-api-primer-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,37],"tags":[76,88,2051,183,2050,1654,297,1840,576,578,652,997,1319],"class_list":["post-26343","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-android","tag-api","tag-blob","tag-camera","tag-createobjecturl","tag-data-uri","tag-data-url","tag-filereader","tag-html","tag-html5","tag-javascript","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/26343"}],"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=26343"}],"version-history":[{"count":5,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/26343\/revisions"}],"predecessor-version":[{"id":26348,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/26343\/revisions\/26348"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=26343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=26343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=26343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}