Wednesday, March 29, 2023

Linux OS: Image Compression With jpegoptim And optipng

Linux image converter.

    The easiest way for me to compress images on Linux is by using this text-based program. While there may be other GUI options available, I find this text-based tool quite effective. Why? Ease of Use: It’s straightforward and simple to operate, Lightweight: It doesn’t consume much system resources. Let’s explore its features...


Installing The Program

I use a Debian-based Linux distribution, so installation procedures might differ if you're using a different distro. To start, open the terminal and update the repository. (Updating the repository isn’t always crucial, but it’s a good practice.) Here’s how:
sudo apt-get -y update
Then after finish, we can now install the program:
sudo apt-get -y install jpegoptim && sudo apt-get -y optipng
Here is how the installation looks:

jpegoptim and optipng installation.


Compressing An Image With jpegoptim

Let’s say we have a JPEG and PNG image that we need to compress to a smaller size. Please note that more aggressive compression will reduce image quality, so you’ll need to ensure that the compression level meets your needs.

For example, I have a wallpaper named 'Bliss XP.jpg' that I want to compress from 2.1 MB to 250 KB. Let’s proceed:

jpegoptim --size=250k 'Bliss XP.jpg'
Here is the process:
 
jpegoptim compress a jpg image.

Now that the image has been compressed to the desired size, it is ready for use.


Compressing An Image With optipng

For another image, specifically a PNG file (e.g., My Bike Tour.png), we use optipng for compression. Unlike jpegoptim, optipng does not require specifying a target size. The process is as simple as:

optipng 'My Bike Tour.png'
Here is the process:
 
optipng compress a png image.


Batch Compressing Files

If you need to compress multiple image files, you can use an asterisk (*) for batch processing with either jpegoptim or optipng. For example, to compress all JPEG images in the Desktop/Images directory to 100 KB each, you can use:
jpegoptim --size=100k Desktop/Images/* 

I understand that Linux might not be everyone's choice, but I wanted to share this information. If you have any difficulties with terminal navigation, you can read this article.

I hope you found this helpful. Have a great day, and see you next time!