I started to do this but the image wouldn't display. I was doing stuff like:
img = document.getElementById('input-image');
canvas = document.createElement('canvas');
context = canvas.getContext('2d');
canvas.width = img.width;
canvas.height = img.height;
context.drawImage(img, 0, 0 );
img2 = document.createElement("img");
img2.src = canvas.toDataURL();
document.body.appendChild(img2);
I was trying to save canvas.toDataURL() to the database of original data as text and then load it into an <img> tag. It wouldn't display.