In the following code, I have set the max image width to 640. I am converting the blob to base64 string and then sending it to the server. On the server I am getting the image of the original width i.e. 1280. It looks like the constraints are not applied on the captured image. How do I force the returned image blob to have size of 640?
function takepicture(mediaStream) {
imageCapture = new ImageCapture(mediaStream.getVideoTracks()[0]);
imgCapture = imageCapture.takePhoto({ imageWidth : 640}).then(function(blob) {
reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function() {
base64data = reader.result.split(',')[1];
// base64data is uploaded to server
}
}).catch(function(error) {
console.log('error: ', error);
});
}
question from:
https://stackoverflow.com/questions/66049005/javascript-dimensions-of-blob-returned-by-the-promise-of-imagecapture-takephot 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…