How to Optimize and Compress JPEG or PNG Images in Linux Commandline

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Senthil Kumar

A Linux Consultant, living in India. He loves very much to write about Linux, Open Source, Computers and Internet. Apart from that, He'd like to review Internet tools and web services.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

29 Responses

  1. Bruce Bates says:

    This is a very nifty little app, but sadly I find the compressions to be minimal to say the least. On average with most of my images, it would only reduce the file size by about 3% whereas when i use something like ffmpeg or imagemagick I am able to compress those same files down by about 80%.

  2. Aerry says:

    Hello, may I ask?

    How to specify the image compression level in png format

    For example, 1-100. What should I do if I want to press the picture to 60%?

  3. Ian says:

    Copying your commands didn’t work for me/Arch Linux. Changing *.JPG to *.jpg did.

    However it only reduced the size about 3%, so I used jpegoptim --size=750k *.jpg.

    The pics still look great on the screen. Thank you very much!

  4. Florian says:

    Very nice! Does the batch operation work recursively?

    • Jonathan says:

      + 1 for recursive please?

      • Aamnah says:

        You can use the find command to recursively find all .jpeg and .jpg files and then pass them to jpegoptim, that should do it for you.

        The command will look like this

        # Jpegoptim
        find images_folder/ *.{jpeg,jpg} -exec jpegoptim {} \;

        # OptiPNG
        find images_folder/ *.png -exec optipng {} \;

        Replace `images_folder` with the path for whatever directory you have your files in

  5. yunik maharjan says:

    when I run the command I get something like this:

  6. cloud consulting says:

    Type the following command:

    $ apt-get install jpegoptim

    Sample outputs:—-

    [sudo] password for vivek: 
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following packages were automatically installed and are no longer required:
      libavutil-extra-51 libggiwmh0-target-x libggi2 libgii1 libvo-aacenc0
      libgii1-target-x mplayer-skin-blue libggiwmh0 libggi-target-x
    Use 'apt-get autoremove' to remove them.
    The following NEW packages will be installed:
    0 upgraded, 1 newly installed, 0 to remove and 5 not upgraded.
    Need to get 14.0 kB of archives.
    After this operation, 77.8 kB of additional disk space will be used.
    Get:1 squeeze/main jpegoptim amd64 1.2.3-2+b1 [14.0 kB]
    Fetched 14.0 kB in 1s (11.2 kB/s)    
    Selecting previously deselected package jpegoptim.
    (Reading database ... 333683 files and directories currently installed.)
    Unpacking jpegoptim (from .../jpegoptim_1.2.3-2+b1_amd64.deb) ...
    Processing triggers for man-db ...
    Setting up jpegoptim (1.2.3-2+b1) ...
  7. lovet says:

    Finally, I have been looking for such tools for image optimization on Linux. Until now, i have always required intenet for image optimizations. Thanks for the post.

  8. David B. says:

    Hello, just wanted to thank you for the article. I needed a way to optimize my images to pass google’s pagerank and this helped immensely. Once again thanks for the easy to read tutorial.

Leave a Reply to Florian Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.