Speed Up Website by Automatically Optimizing PNG Images for Free w/o TinyPNG!

Speed up your CENTOS served website’s PNG images using PNGQUANT instead of paying for TinyPNG API every month!

Kabir (ko-bir)
Apr 9, 2020 · 2 min read

our clients’ execs are working from home, sometimes their internet connections are being slow, and so instead of blaming their congested connections, they get on the wire with us about site performance. So we had a good excuse to review site performance, and as always, we found things to optimize. This time it was PNG images, and one of the client designers working from Canada recommended TinyPNG API for automated PNG optimization. I was intrigued by it but then realize it would cost us a pretty penny to subscribe for the SaaS on a monthly basis. We then looked for an open-source alternative and found PNGQUANT at:


Since we standardize our servers using CentOS stable version, we needed PNGQUANT for CentOS. Luckily there was a ready-to-go RPM package that we installed using:

yum -y install pngquant

Once installed, we tested it on some sample PNG files and noticed the default behavior is pretty good. So we decided to run it on our PNG assets. But before we run PNGQUANT on every PNG file, we wanted to take stock of what the current total size for all our PNG assets was using the following command:

find . -type f -name "*.png" -ls | awk 'BEGIN{ sz = 0;} {sz +=  $7;} END{printf("Total size %d\n", sz);}'

The total size of all PNG assets returned by the above command was 34,502,683 (34.5MB)

Now we were ready to run the PNGQANT command on all the PNG files using the following command

find . -type f -name "*.png" -exec  pngquant -f  --ext .png   {} \;

Then we ran the previous find/awk command to determine the total size again, and this time, we got the total to be 13,584,283 (13.5MB).

So the savings was: 20,918,400 (20MB), which is approx. 60% savings!

The images looked great and reduced our page load significantly!


EVOKNOW is a multinational e-commerce service provider and…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store