0

I'm working with Express js & i'm trying to download and resize pictures using "jimp" package then store theme inside an array( res) in order to store new paths later in the data base. my problem is async / await doesn't work as expected : the log appears before the resize

var Jimp = require("jimp");

const pics = require("./pics.json");

async function download_resize(obj) {
 let res = []
 await pics.data.map(async(k,j)=>{

   await k.urls.map(async(u,i)=>{
     await Jimp.read(u, async (err, lenna) => {
       if (err) {

         throw err;
       } else {

         await  lenna
           .cover(500, 300) // resize
           .quality(100)
           .write("./public/1_" + i + "f.jpg"); // save
           res.push([null,j,"500_"+j+"_"+i+".jpg"])
       }
     });
   })

 })
 console.log(JSON.stringify(res))
}

download_resize(pics);

pics looks like

{
"data":[{"id":1,"urls":[links ....]}]
}

0 Answers0