How to use OptiPNG Image Optimizer In Linux
The syntax of using OptiPng is very simple, we have to just mention the name of the png file after the optipng command.
optipng gfg.png
Let’s compress the file named gfg.png before that, find out the size of the gfg.png file using the ls command:
ls -l gfg.png
The size of gfg.png is 534k now let’s use the optipng tool on that file
optipng gfg.png
We can see that the size gets reduced from 534k to 522k.
Batch PNG Image Compression & Optimization
We can optimize the all .png files in a folder using the following command:
optipng *.png
To save generated output files into another folder, use the -dir option with optipng command:
optipng --dir=compressed gfg.png
To compress selective files with the optipng just mention the file names separated by space:
optipng gfg1.png gfg2.png
To know more about the optipng command, read the man page of optipng using man command:
man optipng
Optimize and Compress JPEG or PNG Images in Linux Command line
Today there are many GUI tools that compress and optimize the images, which are very useful. But if you are terminal addicted and want to compress and optimize the images in the terminal before uploading to the cloud, then you can do it. There are two tools by using which we can compress and optimize images. These are –
- jpegoptim
- OptiPNG