{"id":2039,"date":"2010-06-22T17:02:00","date_gmt":"2010-06-22T17:02:00","guid":{"rendered":"http:\/\/jeffreyatw.wordpress.com\/2010\/06\/22\/binary-image-converter\/"},"modified":"2010-06-22T17:02:00","modified_gmt":"2010-06-22T17:02:00","slug":"binary-image-converter","status":"publish","type":"post","link":"https:\/\/jeffreyatw.com\/blog\/2010\/06\/binary-image-converter\/","title":{"rendered":"Binary Image Converter"},"content":{"rendered":"<h3><a href=\"http:\/\/jeffreyatw.com\/binaryimage\">Binary Image Converter<\/a><\/h3>\n<p>I made another HTML5 toy! It deals with <a href=\"http:\/\/en.wikipedia.org\/wiki\/Binary_image\">binary images<\/a> that print ASCII messages when converted, and vice versa. <a href=\"http:\/\/jeffreyatw.com\/binaryimage\">Try it out<\/a>!<br \/>\nLast night, I noticed <a href=\"http:\/\/chickensnack.livejournal.com\/\" class=\"lj-user\">chickensnack<\/a>&#8216;s favicon on <a href=\"http:\/\/www.chickensnack.com\">his site<\/a> &#8211; I converted it to a binary string by hand (by literally typing out the 1&#8217;s and 0&#8217;s), and then feeding it through a binary-to-ASCII converter I found through Google. I decided that there must be a better way!<br \/>\nI wrote this toy to function almost entirely in JavaScript, so everything except form submission and image verification happens in JavaScript. This includes the actual pixel manipulation to read or generate a bitmap, thanks to <a href=\"http:\/\/en.wikipedia.org\/wiki\/Data_Uri\">data URI<\/a> and <a href=\"http:\/\/en.wikipedia.org\/wiki\/Canvas_element\">canvas<\/a>.<br \/>\nI learned how ASCII and binary are converted from one another &#8211; JavaScript has a handy function to parse a binary digit into an integer (parseInt(x, 2)), but not the other way around. I also learned how to convert images and canvas data into base64-encoded data URIs, meaning that I don&#8217;t need to temporarily host an uploaded image on my server &#8211; just process it in memory and spit it back out in the response.<br \/>\nThis toy (currently) only works with ASCII, meaning you&#8217;re out of luck if you try throwing Unicode in there. And also due to the way that browsers display non-printing ASCII characters, you&#8217;ll run into problems if you try encoding any old image into ASCII. Perhaps I&#8217;ll create a variation that converts the binary into base64 intermediately, so non-ASCII characters can be displayed properly. This would be incompatible with the version I&#8217;ve made, though.<br \/>\nSome examples for you to try:<br \/>\n<img decoding=\"async\" src=\"http:\/\/jeffreyatw.com\/static\/images\/binary1.png\"><br \/>\n<img decoding=\"async\" src=\"http:\/\/jeffreyatw.com\/static\/images\/binary2.png\"><br \/>\n<img decoding=\"async\" src=\"http:\/\/jeffreyatw.com\/static\/images\/binary3.png\"><br \/>\n<img decoding=\"async\" src=\"http:\/\/jeffreyatw.com\/static\/images\/binary4.png\"><br \/>\nSource for this can be found here:<\/p>\n<ul>\n<li><a href=\"http:\/\/bitbucket.org\/jeffreyatw\/jeffreyatw\/src\/tip\/binaryimage\/\">Django view<\/a><\/li>\n<li><a href=\"http:\/\/bitbucket.org\/jeffreyatw\/jeffreyatw\/src\/tip\/templates\/binaryimage\/\">HTML\/JS templates<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Binary Image Converter I made another HTML5 toy! It deals with binary images that print ASCII messages when converted, and vice versa. Try it out! Last night, I noticed chickensnack&#8216;s favicon on his site &#8211; I converted it to a binary string by hand (by literally typing out the 1&#8217;s and 0&#8217;s), and then feeding&hellip; <a class=\"more-link\" href=\"https:\/\/jeffreyatw.com\/blog\/2010\/06\/binary-image-converter\/\">Continue reading <span class=\"screen-reader-text\">Binary Image Converter<\/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":[2],"tags":[48,57,78,80,111],"class_list":["post-2039","post","type-post","status-publish","format-standard","hentry","category-blog","tag-html5","tag-javascript","tag-portfolio","tag-programming","tag-update","entry"],"_links":{"self":[{"href":"https:\/\/jeffreyatw.com\/blog\/wp-json\/wp\/v2\/posts\/2039","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jeffreyatw.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jeffreyatw.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jeffreyatw.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jeffreyatw.com\/blog\/wp-json\/wp\/v2\/comments?post=2039"}],"version-history":[{"count":0,"href":"https:\/\/jeffreyatw.com\/blog\/wp-json\/wp\/v2\/posts\/2039\/revisions"}],"wp:attachment":[{"href":"https:\/\/jeffreyatw.com\/blog\/wp-json\/wp\/v2\/media?parent=2039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jeffreyatw.com\/blog\/wp-json\/wp\/v2\/categories?post=2039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jeffreyatw.com\/blog\/wp-json\/wp\/v2\/tags?post=2039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}