NodeJS Batch Processing for pngquant.
This is a simple sequential or parallel batch processing PNG compressor for NodeJS using pngquant (website / GitHub ).
It was made for Windows, but since it uses NodeJS shelljs portable unix shell, then it can be easily ported to other OSs by changing the pngquant.exe to similar executable in OSX/Linux environments.
Sequential: node sequential.js
Parallel: node parallel.js
This will execute the pngquant.exe for each image with the following options:
--speed 1 --strip --quality=60-80 ./input/[name].png -o ./output/[name].png
,
to change this options you have to change the worker.js
file to meet your needs.
Tested with Intel Core-i5 4690K 3.5GHz 4 core processor.
Sequential version: ExecTime: 341963.668ms = 341.963668s = 5min41s
Parallel version: ExecTime: 117284.8515ms = 117.284852s ~= 2min
Sequential version: ExecTime: 23342.678ms ~= 23s
Parallel version: ExecTime: 8079.25ms ~= 8s
npm install -g shelljs
If the division of number of png images by the number of cpu cores is not an integer then the last core has to convert the remaining images (maximum will be numCores - 1 images).
Example:
Then the first 3 cores will convert 5 images each and the last one will convert 8 images
Does not work with sub folders inside input folder.