How to compress PNG image file in Linux

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Introduction

PNG or Portable Network Graphics is an image file format meant to replace GIF

PNG utilizes lossless image compression, which results in high-quality images though sometimes they can be relatively big.

Also if you have a lot of images, and want to compress them without losing its original quality There are plenty of GUI applications available which will help you to optimize the images.

Here are two simple command line utilities to optimize images and they are:

PNGquant and OptiPNG are programs that optimize PNG images to smaller size without losing any information or their original quality.

(1) PNGquant

pngquant can help you to reduce the size of a PNG image in Linux by performing lossy and lossless compression. 

pngquant usually is the best option as it seems to optimize the file size the most without sacrificing much on quality.

  • First, Install pngquant package for your system.
sudo apt update && sudo apt install --assume-yes pngquant   #Ubuntu
yum install epel-release
yum install pngquant


dnf install epel-release   #Fedora 22+ versions
dnf install pngquant       #Fedora 22+ versions
  • Check current image file size.
ls -lh 
  • Compress PNG file using pngquant.
pngquant unixcop_image.png
  • Also Check size of generated file to compare.
ls -lh

Successfully compressed

NOTE: -fs8 is appended to the compressed filename.

  • For more options of pngquant tool.
pngquant --help

(2) OptiPNG

OptiPNG is a command line tool used to optimize and compress PNG files without losing its original quality.

  • Install OptiPNG in your Linux system
sudo apt-get install optipng  #Ubuntu
yum install optipng    #CentOS/RHEL7
dnf install optipng    #Fedora 22+ versions
  • Check current image file size.
ls -lh
  • Compress PNG file using OptiPNG .
optipng unixcop_image.png
  • Then check size of generated file to compare as shown below
ls -lh
  • To compress batch or multiple PNG images at once, just go the directory where all images resides and run the following command to compress.
optipng *.png

Conclusion

As shown from screenshots above, seems that PNGquant is better than OptiPNG, choose the tool you want and go ahead with compressing your images then save them before uploading them to cloud or any local storages.

Using these two tools, you can either optimize a single or multiple images at a time.

Thanks

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
MQ-Jr
MQ-Jr
unixcop Admin

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook