https://github.com/blueimp/JavaScript-Canvas-to-Blob
var canvas = document.createElement('canvas')
/* ... your canvas manipulations ... */
if (canvas.toBlob) {
canvas.toBlob(function(blob) {
// Do something with the blob object,
// e.g. creating a multipart form for file uploads:
var formData = new FormData()
formData.append('file', blob, fileName)
/* ... */
}, 'image/jpeg')
}