N Kaushik

How to optimize png files for your web and mobile projects

April 23, 2021

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:

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.

github repo Download page

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:

pngquant *.png

There are different options available. You can use pngquant -h to get the full list.

Set max-min quality:

--quality min-max

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 --ext newname.png

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


Subscribe to my Newsletter