How to optimize png files for your web and mobile projects:
I try to avoid png images wherever possible, and replace them with vector images, in a web based project or mobile project. Android provides a way to compress the images while you are making the build. But, still if you are using png files, you can try other external tools to compress them before using.
pngquant is a compressor for png files that can be used to compress png files without losing quality. It converts the png files to a 8 bit PNG format. The output is around 60-80% smaller than 24-bit or 32-bit png files.
How to compress:
You can compress single or multiple files. For example, it can compress all png files in a folder with the below command:
There are different options available. You can use
pngquant -h to get the full list.
Set max-min quality:
You can set the quality for both min and max from 0 to 100.
Change the extension:
If you want to change the extension of the output file, you can use
Replace all input files:
You can use
--ext=.png --force, but it will replace all input files.
There are many other commands available. You can check the full commands here