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...

28 Responses

  1. bhishma says:

    and there are two very interesting ideas to compress & optimize pictures by parallel execution & CUDA

  2. bhishma says:

    many thanks for the very interesting article & discussions!
    there is a very promising project:


    This tutorial helped me a lot, one of sites I have to optimize it’s images for more faster loading, result now:

    It is better the doing it manually. For me I set those options for JPG images:

    # jpegoptim -m 70 -s *.jpg *.jpeg *.JPG *.JPEG

    -s option will strip other information reside inside image, and also it will save you extra bandwidth and results in faster loading.

    PNG images:

    # optipng -o4 *.png
  4. masa says:

    Just wondering if the target image is already optimized then will it be skipped?

  5. Tiwo Satriatama says:

    Excellent! Must-try Linux tips. Thanks for sharing

  6. Vule says:

    I cannot open the pic after optimisation. Is it because the pic has only 63k?

    • Ravi Saive says:


      Size doesn’t matter, you can optimize any size images from 10KB to 10MB, what error you getting while opening optimized image? which tool you used to view images? do you tried with different image viewers?

  7. Giorgos says:

    Hi! :-)
    Take also a look, at Trimage.

    • Ravi Saive says:


      Thanks for the tip about Trimage tool, but we’re getting 404 error while accessing the page, seems no more development and also I found that the last update was 5 years ago on Github

  8. Yavor says:

    I use ‘convert’
    With a small script take all the files from ./orig and create thumbnails in ./pics and a larger picture in ./pics-big
    it also creates the entries for the html file
    it reduces the image to 28% and 64% of their original dimensions – but that is how my camera is set up

    cd orig;
    for file in *; do convert -strip -scale 64%x64% -quality 75 $file “../pics-big/”$file;
    convert -strip -scale 28%x28% -quality 75 $file “../pics/”$file;
    echo ” ” >> ../html.txt;

    • Ravi Saive says:


      Thanks a ton for sharing the script with us, I was looking for such script since long time for my camera images, which are huge in size..let me try and get back to you..

  9. Jalal Hajigholamali says:

    Thanks a lot…
    very useful article….

  10. nicu says:

    with OptiPNG i was familiar with, so after reading your article, I gave a try to jpegoptim: it was useless for my final JPEGs, which are produced with GIMP, and are destined to web use – 0.00% improvement. on a batch of JPEGs taken straight from the camera, for the batch I tested, the average space savings was 2.36%
    my conclusion: it would be useless for a webmaster trying to minimize bandwidth use, it wasn’t able to do a thing.

    • Ravi Saive says:


      I totally agree with your point that jpegoptim not a best tool for JPEG or JPG compression, it just reduce the size around 5-10% that’s totally useless to use, whereas OptinPNG works great it optimize images nearly 30-40% but still I can say it’s not a good choice to use for websites, where speed is more important. Even I tried different online jpeg or png compression tools, still not a good results specially for jpeg images…

Got something to say? Join the discussion.

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.