In the last article we described how to compress JPEG images. Now we will tell you how to solve a similar problem, but already in relation to pictures with PNG format.
PNG - a very popular extension of pictures. The format was developed as a replacement for GIF. The size of PNG pictures is often very different in terms of color depth, interlacing, as well as due to a certain compression algorithm.
OptiPNG is a unique console program that can be used to compress PNG pictures. All major and minor tasks can be realized with OptiPNG. You can do it as quickly and without loss in quality and in the case of JPEG pictures.
Are you working in Ubuntu? You can install the program without much trouble from the repository. You need to execute the following command:
$ sudo apt install optipng
The syntax of the utility is quite simple. It can be performed in the same way as in the case of jpegoptim:
$ optipng file_name options.png
Let's look at the utility options:
-backup
- save copies of modified files;-dir
- folder for writing files;-force
- force write outgoing file;-out
- write outgoing
file to the specified file;-simulate
- do not perform any actions, but only show the result;-o
- set compression level from 0 to 7.Let's perform png optimization. Let's find out how much the file weighs:
$ df -h image.png
To compress the file we use:
$ optipng image.png
We look at the size, we do not see any differences, the image is quite small but when increasing the size the difference will be visible:
Compression png occurs without loss of quality, you will get the same picture, but smaller in size. It is necessary to designate the degree of optimization, which affects the time loss associated with the program optimization of pictures. Degree put 0 to 7. The higher it is, the more cost in time and resources will need a PC.
$ optipng -o 7 impge.png
Batch processing of pictures is performed in the same way with jpeg:
$ cd images/
$ optipng *.png
That's it, again, nothing complicated.