I have a backend Node.js endpoint that is supposed to accept images in base64 containing QR code and return a 16-digit alphanumeric string. (I'm using qrcode-reader package)
However, I'm encountering an error which says I need to pass an image buffer with width and height. I'm not sure how I can get the width and height from a base64 image-string, since many of the image packages on npm work with the files in .png or .jpg format.
Any suggestions on how I can obtain the width and height of an image in base64?
function readQR(){
return function(req, res){
// Load base64 image
var base64Image = req.body.image;
var decodedImg = decodeBase64Image(base64Image);
var imageBuffer = decodedImg.data;
qr.callback = function(err, result){
if(err) console.log(err);
// Regex check whether it is 16 letter alphanumeric
if(/^(\w{16,16})$/.test(result)) res.json(result);
else res.json({
error: 'Invalid dmac address'
})
}
qr.decode(imageBuffer);
}
}