Not only images in JPG format can be optimized, so can PNG files. There are several applications for this purpose, in this post we will focus on one in particular: OptiPNG.
OptiPNG is a small tool that allows us optimize PNG images —And converting others to this format — without losing any quality at all along the way. It is a tool that does not have a graphical interface, although its use through the comfort it's really simple. The base command to reduce the size of our PNG images is:
optipng [archivo]
As simple as that. Although OptiPNG has a lot of configurable parameters that will help us to customize the optimization process. For example, if we wish keep original file we will use the option
-keep
-k
-backup
Suppose our image is located at the root of our home directory and we want to optimize it without losing the original file. For this purpose we will use the command:
optipng -k $HOME/imagen.png
Although OptiPNG chooses the best compression level, we can also set it manually. For this we make use of the option
-o
, being able to set values from 1 to 7, with 7 being the maximum level. Going back to the previous example, suppose we want to add a custom compression of 5 as well; then we execute:
optipng -k -o5 $HOME/imagen.png
If we want to execute the previous command to all images in a directory, we use:
optipng -k -o5 $HOME/directorio-de-las-imágenes/*.png
To access the full list of OptiPNG options we only have to execute
optipng --help
It should be noted that the compression carried out by OptiPNG is without loss of quality, so surely we will not obtain results as drastic as those offered by some online services -such as TinyPNG-, in which the images do lose a bit of quality, something Notable especially in those that contain gradients.
Installation
OptiPNG is in the official repositories of Ubuntu, so to install the tool just run in our terminal:
sudo apt-get install optipng
More information - Adjusting the screen brightness with Xbacklight, How to free up RAM in Ubuntu
Thank you very much for sharing your knowledge. 🙂