Development
How to Optimize JPG and PNG Images
Learn how to quickly and easily optimize JPG and PNG images on your website without losing the original quality of your files.
If you need to optimize JPG and PNG images without losing their original quality so your website loads faster, you should know about these two utility software programs (available only for Linux operating systems):
- Jpegoptim - a utility designed to optimize / compress JPG files without losing quality.
- OptiPNG - a utility designed to optimize PNG images to reduce their file size without losing any information, including transparency.
Installing
How to install Jpegoptim
Below, we’ll walk you through how to install Jpegoptim on a Linux server running Ubuntu. In your terminal’s command line, run the following command:# apt-get install jpegoptim
or
$ sudo apt-get install jpegoptim
How to install OptiPNG
Below, we’ll walk you through how to install Jpegoptim on a Linux server running Ubuntu. In your terminal’s command line, run the following command:# apt-get install optipng
or
$ sudo apt-get install optipng
Using the tools
Using Jpegoptim
In your terminal’s command line, run the following command: For a single file:$ jpegoptim filename.jpeg
$ jpegoptim filename.jpeg
For multiple files in the same directory:
$ jpegoptim *.JPG
Using OptiPNG
In your terminal’s command line, run the following command: For a single file:$ optipng filename.jpeg
$ optipng filename.jpeg
For multiple files in the same directory:
$ optipng *.JPG
Important tips
- Always back up all your images before using any optimization program. If something unexpected happens, you’ll be able to quickly restore the original files.
- The utilities may change file permissions, so always make sure the image is available in your browser.