Skip to content

Instantly share code, notes, and snippets.

@AnatoliyLitinskiy
Forked from iwek/imagedata-to-filename.js
Created September 23, 2016 17:10
Show Gist options
  • Save AnatoliyLitinskiy/273621a1dbc8dc7f279000b778c6a3b0 to your computer and use it in GitHub Desktop.
Save AnatoliyLitinskiy/273621a1dbc8dc7f279000b778c6a3b0 to your computer and use it in GitHub Desktop.
Convert CANVAS data to binary data and then to a filename using a Blob
function binaryblob(){
var byteString = atob(document.querySelector("canvas").toDataURL().replace(/^data:image\/(png|jpg);base64,/, ""));
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
var dataView = new DataView(ab);
var blob = new Blob([dataView], {type: "image/png"});
var DOMURL = self.URL || self.webkitURL || self;
var newurl = DOMURL.createObjectURL(blob);
var img = '<img src="'+newurl+'">';
d3.select("#img").html(img);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment