Closed mateuszBetlej4 closed 1 year ago
Hi, this isn't really an issue with JIMP as much as it is just a coding issue. You are correct in your assumption that the program you wrote will by processing all the files at the same time, and this is likely the cause of your memory and CPU issues. What you want to do is instead of calling processimage inside the readDir function, instead add them to an array. Once the directory has been read and the files all found, start work on the image processing - call processimage on the first file in the array, and do not call again until the process is complete (simple way to do this would be to have some flag variables set when the process starts and ends, and maybe just have a setInterval checking the flags. A nicer way is to use a loop and async.
This will still take a long time as using getPixelColor is not incredibly fast, but this will at least allow the program to not hog all your laptops memory so you can at least do other stuff in the mean time. I also understand that if you opened this 25 days ago, you probably have resolved this or moved past this issue!
Expected Behavior
It reads a folder with multiple images (706) and calculates the dark and white pixels and convets the number of white pixels into a percentage.
Current Behavior
The code does what I need it to do except it's very slow. I have noticed that it tries to open all images at once and just then proceed to the calculations. I have a 8gb ram laptop. While the code reads the images the ram peaks up to 6gb and the program freezes for about 10min before it proceeds with the calculations.
maybe someone could help me to read the images one at a time and do the calculation and carry on with the rest of the images in the folder so that it doesn't fill up the memory. Thanks