I'm using Jimp to manipulate some photos.
I have an array with photos. Like this:
var images = ['.../pic-1.jpg', '.../pic-2.jpg', '.../pic-3.jpg', '.../pic-4.jpg'];
And this is the code for manipulating them:
images.forEach(function(image){
jimp.read(image, function(err, img){
img.quality(90, function(){
console.log("done with this image!");
});
});
});
This works nice it logs when each image is done. However, it's blocking the code and if I try this:
var processed = 0;
images.forEach(function(image){
jimp.read(image, function(err, img){
img.quality(90, function(){
processed++;
document.querySelector('p').textContent = 'processed images: ' + processed;
});
});
});
it doesn't update the text until all the images are processed. How can I work this around so I can update the text each time an image gets processed?