• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Friday, May 9, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

Compressing Images On The Linux Command Line

How VPS by How VPS
January 1, 2020
in Linux
0
0
SHARES
255
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Installing jpegoptim and OptiPNG
  2. Using jpegoptim to compress JPEG files
  3. Using OptiPNG to optimize PNG, BMP, GIF, PNM, and TIFF files
  4. Want to contribute?


If you have a lot of high-resolution images stored on your Linux computer, you may be running out of storage due to the large amount of disk space used by your photo library. In this case, you may be looking for a solution that allows you to compress these images to conserve disk space without affecting their quality.

Further, traditional compression solutions often allow compressing image files one-by-one, which can be a rather cumbersome and time-consuming process. Therefore, compressing your images in batches may be a great idea to save time and effort.

That’s where jpegoptim and OptiPNG come in handy. Both jpegoptim and OptiPNG are command line-based utilities that can be used to optimize and compress pictures in batches without affecting their original quality (also known as lossless compression). Jpegoptim handles JPEG files while OptiPNG processes pictures in the format of PNG, BMP, GIF, PNM, and TIFF.

Let’s go over the process of installing jpegoptim and OptiPNG to compress pictures in Linux using the command line.

Note: This tutorial assumes you are using a non-root user with sudo privileges.

Installing jpegoptim and OptiPNG

On CentOS or other RPM-based Linux distributions:

sudo yum install epel-release
sudo yum install jpegoptim optipng

On Debian or other APT-based Linux distributions:

sudo apt-get install jpegoptim optipng

Using jpegoptim to compress JPEG files

In this example, your original JPEG (.jpg) files are stored ~/jpeg.

a) If you want to compress a single file, let’s say example.jpg you would be using the below command:

cd ~/jpeg
jpegoptim example.jpg

Notice: The original example.jpg will be replaced with a compressed version by default.

b) If you want to compress all .jpg files in the source directory:

cd ~/jpeg
jpegoptim *.jpg

All the original files will be overwritten and replaced with the compressed version.

c) If you wish to keep the original files, you can specify a target directory to store the compressed version to as follows:

cd ~/jpeg
mkdir optim
jpegoptim *.jpg -d ~/jpeg/optim

d) For more information on how to use the jpegoptim command, you can use the -h flag to view its help file:

jpegoptim -h

Using OptiPNG to optimize PNG, BMP, GIF, PNM, and TIFF files

Just like jpegoptim, OptiPNG will overwrite the original files and replace then with the compressed version in the source directory by default. Meanwhile, for BMP, GIF, PNM, and TIFF files, OptiPNG will generate optimized .png version of the file with the same name, leaving the original files in tact. These file would have to be manually removed one the compression process is compelted.

Below are a few examples on how to use OptiPNG to apply lossless compression to your images:

In this example, your original JPEG (.jpg) files are stored ~/pic.

a) If you want to compress a single file, let’s say example.png you would be using the below command:

cd ~/pic
optipng example.png

Notice: The original example.png file will be replaced with a optimized version.

b) Optimize a .bmp file example.bmp:

cd ~/pic
optipng example.bmp

A file named example.png will be created in the source directory while the original example.bmp stays in tact.

c) If you want to compress all .png files in the source directory:

cd ~/pic
optipng *.png

All the original files will be overwritten and replaced with the compressed version.

d) If you prefer to keep the original files in tact, you can do so by using the -keep flag as follows:

cd ~/pic
optipng -keep *.png

The original files will remain in tact and suffixed with a .bak. For example example.png.bak.

e) If you wish to keep the original files, you can specify a target directory to store the compressed version to as follows:

cd ~/pic
optipng -dir ~/pic/optim *.png

All the original files will remain in tact in the source directory while the compressed version will be saved in target directory.

f) For more information on how to use the OptiPNG command, you can use the -h flag to view its help file:

optipng -h

This concludes our tutorial.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article
Previous Post

Getting Started with cPanel/WHM

Next Post

Install Nginx + PHP FPM + Caching + MySQL on Ubuntu 12.04

Next Post

Install Nginx + PHP FPM + Caching + MySQL on Ubuntu 12.04

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet