Graphics

Let’s Reduce The Size Of .png Files

In today’s article, we’re going to learn how to reduce the size of .png files. PNG stands for Portable Network Graphics and they can be pretty large. They are raster image format files using lossless image compression. So, today we’ll be doing just that, compressing .png files, in the terminal.

As stated, PNG stands for Portable Network Graphics. Some folks will say that it stands for “PNG’s Not GIF” but they’re incorrect – but are correct about the motive. The .png format was developed to be a free-of-patent alternative to .gif files – some 25 years ago, as of the time this article is published. You can read more about the file format at the PNG Wikipedia Page.

The tool we’ll be using is known as ‘pngquant‘, which should be available in most default repositories. You can check the man page, but it defines itself as:

pngquant — PNG converter and lossy image compressor

You’ll note that it says ‘lossy’ and that means you can lose some image quality with this compression – but from my testing it spits out a perfectly usable image, even while compressing it a great deal. It’s pretty handy. I haven’t tested it as a batch process on a bunch of files, but I have tested it on some files. In each case, I got a perfectly usable image that spit out the other side.

So, with that, let’s move on into the meat of the article, where we’ll learn to …

Reduce The Size Of .png Files:

As pngquant is a terminal-based application, it stands to reason that you’re gonna need an open terminal. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

I’ll give you the installation instructions for Debian/Ubuntu/Mint, but you should be able to find the package in most default repositories. To install in those particular distros:

sudo apt install pngquant

Once ‘pngquant’ has been installed, navigate to a directory where you have some .png files waiting to be compressed. Once you’re there, run this command:

ls -lh foo.png

That’ll tell you the size of the .png in question. Now, you’re going to compress it with the following command:

pngquant foo.png

By default, ‘pngquant’ will retain the original file and create a new file that has appended – fs8 to the file name. So, foo.png becomes foo-fs8.png. You can change that behavior with the --ext flag. 

Here’s an example where an already small .png file was reduced even further by way of pngquant:

As you can see, it reduced the file size by about half. The resulting quality was fine.

You can find GUI software that will do this for you, but this is a quick and easy way to reduce the size of .png files in the terminal. While not opensource, there’s XnViewMP and I’m pretty sure XnConvert works with Linux as well. If not, XnViewMP does and has batch conversion as an option – while the latter is specifically for batch conversion.

Closure:

And there you have it… You have a way to reduce the size of .png files in your terminal. Just what you always wanted! I don’t see my average reader doing a whole lot of this, but it’s an option if you want. I use a service that switches my images to WebP as it’s faster and lighter. It’s done by my CDN for me, which is nice and one of the reasons the site loads quickly.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. The first person to read this sentence should contact me and I’ll donate five dollars to their favorite charity that accepts PayPal. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

Recent Posts

Enable/Disable Your Network Interface

Today we'll cover one way to enable or disable your network interface in the Linux…

7 months ago

Check Your NIC Speed In The Terminal

Today's exercise is a nice and simple exercise where we check your NIC speed in…

7 months ago

Easily Monitor Your Wireless Connection

Have you ever wanted to easily monitor your wireless connection? Well, now you can learn…

7 months ago

Count The Files In A Directory

I think I've covered this before with the ls command but this time we'll count…

7 months ago

Get System Information With The ‘uname’ Command In Linux

Today we'll be learning about a basic Linux command that's known as 'uname' and it…

7 months ago

hardinfo Has Been Rebooted As hardinfo2

If you've used hardinfo in the past, it may interest you to know that hardinfo…

7 months ago