Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

How to Batch Compress & Convert Nested Image Folders to WebP in the Browser (No 20-File Upload Limits)

If you've ever needed to compress a multi-folder project—like a public/assets/ directory for a web app, a sprite folder for an indie game, or a 10-episode comic archive—you've probably hit the same frustrating wall with

If you've ever needed to compress a multi-folder project—like a public/assets/ directory for a web app, a sprite folder for an indie game, or a 10-episode comic archive—you've probably hit the same frustrating wall with cloud image compressors:

  1. The 20-File & 5MB Paywall: Most online tools (like TinyPNG or iLoveIMG) cap free batches at 20 files and 5MB per image.
  2. Flattened Directory Structures: Even if you drop images from nested folders (Episode_01/, Episode_02/, ui/icons/), cloud tools dump everything into a single flat .zip, forcing you to manually re-sort hundreds of files.
  3. Privacy & Upload Wait Times: Uploading 500MB of raw PNGs to a remote server just to convert them to WebP or JPEG wastes bandwidth and exposes private assets.

To solve this cleanly without any backend server costs, I built a 100% client-side Batch Folder Image Compressor & Resizer as part of CreaPocket.

👉 Try it live here (Free, No Sign-up): CreaPocket Batch Folder Image Compressor

🛠️ How It Works Under the Hood (100% In-Browser)

Modern browsers already have everything needed to process hundreds of high-resolution images locally using your device's own RAM and CPU:

1. Recursive Folder Traversal (webkitGetAsEntry & webkitdirectory)

Instead of only accepting flat file lists, we can traverse entire directory trees dropped onto the page and preserve every file's relative path (folder/subfolder/image.png):

async function traverseFileTree(item, path = "") {
  if (item.isFile) {
    return new Promise((resolve) => {
      item.file((file) => {
        file.relativePath = path + file.name;
        resolve([file]);
      });
    });
  } else if (item.isDirectory) {
    const dirReader = item.createReader();
    const entries = await new Promise((resolve) => dirReader.readEntries(resolve));
    const files = await Promise.all(
      entries.map((entry) => traverseFileTree(entry, path + item.name + "/"))
    );
    return files.flat();
  }
  return [];
}

2. Avoiding the HTML5 Canvas "PNG Bloat Trap" (Smart Size Guard)

One common gotcha with canvas.toBlob(callback, 'image/png', quality) is that browser PNG encoders are strictly lossless and ignore the quality parameter. Re-encoding an already optimized PNG on a <canvas> can actually make the file 10–30% larger!

To prevent negative compression:

  • Smart Size Guard: Whenever dimensions aren't downscaled and the output format matches the input, we compare compressedBlob.size against originalFile.size. If the re-encoded blob is larger, we automatically fall back to keeping the original file untouched.
  • One-Click WebP / JPEG Conversion: Switching a folder of heavy PNGs to WebP (84% quality) or JPEG shrinks total folder size by 65% to 85% while keeping visual quality virtually indistinguishable.

📊 Real-World Compression Benchmark (100-Image Folder)

Here is what happens when you drop a nested folder of 100 high-res illustrations and UI assets (245 MB total raw PNGs) into the browser compressor:

Output Format Quality Setting Output Folder Size Space Saved Transparency Subfolders Kept?
Original PNG Raw 245.0 MB 0% Yes Yes
WebP (Recommended) 84% 38.2 MB -84.4% Yes Yes
JPEG 84% 44.6 MB -81.8% No Yes
Downscaled 50% + WebP 84% 11.5 MB -95.3% Yes Yes

🚀 Two Live Utilities in CreaPocket

Both utilities run completely inside your browser with zero server uploads:

  1. Batch Folder Image Compressor & Resizer

    • Drop entire nested folders or individual images.
    • Bulk convert between WebP, JPEG, and PNG with custom quality sliders.
    • Resize by percentage (75%, 50%) or fit max width/height (1920px, 1280px, 800px) without enlarging smaller images.
    • Export a clean .zip with your exact original folder hierarchy intact.
  2. Webtoon & Manga Vertical Image Slicer

    • Built for digital comic creators publishing on WEBTOON Canvas (800 × 1280 px) and Tapas (940 × 1280 px).
    • Automatically downscales oversized canvas widths and slices long vertical strips into sequentially numbered pages in seconds.

📖 Deep-Dive Guides

If you're interested in the specifics of image compression and comic formatting workflows, check out our full guides:

Feedback and feature requests are super welcome!

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.