I want to compress all png
image files existing in a directory and save all these converted/compressed image files into a different folder with their original image names using pngquant:
Syntax for batch compression:
pngquant.exe --quality=40-55 images\*.png
It compresses all the PNG image files in images
directory and saves compressed files as new files in the same directory with appending -fs8 after the name of original file, e.g.
arrow.png
arrow-fs8.png
arrow.png
is the source file and arrow-fs8.png
is the output file.
I want to save all converted files with their original names in a separate folder.
Does anyone know how to do this with pngquant.exe?
Help output by pngquant
on running it with option -h
:
pngquant, 2.5.2 (October 2015), by Greg Roelofs, Kornel Lesinski.
Compiled without support for color profiles. Using libpng 1.6.18.
usage: pngquant [options] [ncolors] -- pngfile [pngfile ...]
pngquant [options] [ncolors] - >stdout <stdin
options:
--force overwrite existing output files (synonym: -f)
--skip-if-larger only save converted files if they're smaller than original
--output file destination file path to use instead of --ext (synonym: -o)
--ext new.png set custom suffix/extension for output filenames
--quality min-max don't save below min, use fewer colors below max (0-100)
--speed N speed/quality trade-off. 1=slow, 3=default, 11=fast & rough
--nofs disable Floyd-Steinberg dithering
--posterize N output lower-precision color (e.g. for ARGB4444 output)
--verbose print status messages (synonym: -v)
Quantizes one or more 32-bit RGBA PNGs to 8-bit (or smaller) RGBA-palette.
The output filename is the same as the input name except that
it ends in "-fs8.png", "-or8.png" or your custom extension (unless the
input is stdin, in which case the quantized image will go to stdout).
The default behavior if the output file exists is to skip the conversion;
use --force to overwrite. See man page for full list of options.
Here is the commented batch code for the task with additional features.
It is possible to specify source folder as first parameter and output folder as second parameter on starting/calling this batch file.
If the source folder should be the same folder as the batch file and just an output folder should be specified on starting/calling this batch file, specify as first parameter just
.
for current folder.For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
endlocal /?
for /?
goto /?
if /?
md /?
pause /?
popd /?
pushd /?
rem /?
set /?
setlocal /?
pngquant.exe -h