Resize many images at once
An image that takes up just 2MB of disk space as a compressed JPG might take up 50MB of raw RAM when decoded into the browser's memory for resizing.
If you try to resize 100 images at the exact same time, the browser will attempt to allocate 5 Gigabytes of RAM instantly. On most consumer devices, this will crash the browser tab with an OOM (Out of Memory) error.
To safely resize images in bulk, this tool implements a strict Task Scheduler.
Instead of processing everything at once, it puts all files into a queue. It decodes one image, resizes it using an OffscreenCanvas, encodes the final output, and then explicitly nullifies and destroys the heavy canvas data before moving to the next item in the queue.
By carefully throttling the concurrency of the queue, the system gives the browser's Garbage Collector enough time to sweep up and free the discarded memory from Image 1 before it starts allocating heavy memory for Image 2.
This asynchronous pacing ensures that memory usage stays flat throughout the entire batch process, allowing a mobile phone to resize 500 images without crashing.
Why might a 2MB JPEG image use 50MB of RAM when loaded into a Canvas for resizing?