Bulk convert PNG-24 to PNG-8 files with best quality

bulkimage conversionimage-transparencyimagemagickpng

Can anybody recommend a good method of bulk converting a large amount of PNG-24 files to PNG-8 with as little loss of quality as possible and maintaining transparency?

I've tried ImageMagick but the resulting images weren't quite as crisp quality as I'd like. Using Paint.NET I was able to achieve far better results, but I can't bulk process with this tool as far as I know.

The settings I used with ImageMagick in case there's better options to use:
convert file.png -depth 4 file-output.png

I've also been playing with OptiPNG, but I haven't discovered a was of making sure the output images are PNG-8.

Best Answer

pngquant is exactly the tool for this. It generates palettes better than ImageMagick.

pngquant --quality=0-90 *.png

This will convert all png files in current directory, and automatically choose number of colors to achieve quality similar to 90%-quality JPEG.

(if it doesn't accept the --quality switch it means you have terribly outdated low-quality version and you should upgrade).