Resize images to a maximum width of 1920 px (height scales automatically) and compress them to the desired quality.
-
Resize images to a maximum width of 1920 px (height scales automatically).
-
PNG stays PNG
- Default: lossless compression
- Optional: lossy, palette-based quantisation (
--compress-pngor-P)
-
Everything else becomes JPEG using MozJPEG, with adjustable quality.
-
Folder hierarchy from the input directory is mirrored in output.
-
Default paths:
./input→./output(override on the command line). -
Optional renaming:
--rename→<top-folder>-<index>.<ext>. -
Safety prompt: if the output folder already exists, you’ll be asked whether to wipe it first.
Use--force-deleteto skip the prompt and delete automatically.
node imageOptimizer.js [inputDir] [outputDir] [options]-q, --quality <n> JPEG quality 1–100 (default 75)
--compress-png Quantise PNGs (palette) instead of lossless
-P, --png-quality <n> PNG quality 1–100 (default 80, implies --compress-png)
--rename Rename files to <folder>-<index>.<ext>
--force-delete Delete existing output dir without asking
-h, --help Show this help
node imageOptimizer.js -q 80node imageOptimizer.js ./photos ./publish -q 85 -P 70 --rename --force-deletenode imageOptimizer.js -P 60node imageOptimizer.js --rename -q 90node imageOptimizer.js ./raw ./web -q 85 --compress-pngnode imageOptimizer.js --force-deletenode imageOptimizer.js -q 80node imageOptimizer.js ./photos ./publish -q 85 -P 70 --rename --force-delete- Node ≥ 18.17 LTS (or 20+) suggested.
npm installornpm -i