async function imgResize(data){
// Convert base64 to buffer => <Buffer ff d8 ff db 00 43 00 ...
const buffer = Buffer.from(data, "base64");
Jimp.read(buffer, (err, res) => {
if (err) throw new Error(err);
console.log("Original image size: "+res.getWidth()+"x"+res.getHeight())
if (res.getWidth() > 1025){
res.resize(1025, Jimp.AUTO)
console.log("resized image size: "+res.getWidth()+"x"+res.getHeight())
}
res.getBase64(Jimp.AUTO, (err, value)=>{
if(err){return err)}
return value;
})
}
const img = await imgResize(base64data)
I get, SyntaxError: await is only valid in async functions and the top level bodies of modules. But if I remove the async and just print the value without returning it, it works fine. So how I will able to get the value out of that function as return value and hold it in a variable?