Struggling to convert a base64 image captured using a webcam into a jpeg for upload.
The following capture / display photo works (note that I am using webcam.min.js (which returns base64) and not webcam.js (which returns jpeg but relies on Flash) -
function take_snapshot() {
Webcam.snap( function(data_uri) {
// display results in page
document.getElementById('upload_results').innerHTML =
'<img id="imageprev" src="'+data_uri+'"/>';
} );
}
I have tried the following, which may or may not be converting the base 64image to a blob -
function saveSnap(){
var base64image = document.getElementById("imageprev").src;
alert(base64image)
// convert base64 to raw binary data held in a string
var byteString = atob(base64image.split(',')[1]);
// separate out the mime component
var mimeString = base64image.split(',')[0].split(':')[1].split(';')[0];
// write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);
var dw = new DataView(ab);
for(var i = 0; i < byteString.length; i++) {
dw.setUint8(i, byteString.charCodeAt(i));
alert("arrived here");
// write the ArrayBuffer to a blob, and you're done
return new Blob([ab], {type: mimeString});
}
And this doesn't do anything, except halt the jsp
let image = new Image();
image.src = base64image;
document.body.appendChild(image);
How do I get / see / extract the actual jpeg file so I can then upload it (it must be something like number.jpeg)
JDK6 / Javascript (no php please)
Any thoughts appreciated.
Regards Ralph