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

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. Use our Linode referral link if you plan to buy VPS (it starts at only $10/month).
  4. Support us via PayPal donate - Make a Donation
  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...

14 Responses

  1. masa says:

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

  2. Tiwo Satriatama says:

    Excellent! Must-try Linux tips. Thanks for sharing

  3. Vule says:

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

    • Ravi Saive says:

      @Vule,

      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?

  4. Giorgos says:

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

    • Ravi Saive says:

      @Giorgos,

      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

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

    #!/bin/bash
    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;
    done;

    • Ravi Saive says:

      @Yavor,

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

  6. Jalal Hajigholamali says:

    Hi,
    Thanks a lot…
    very useful article….

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

      @Nicu,

      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 *

Join Over 300K+ Linux Users
  1. 177,942
  2. 8,310
  3. 37,548

Are you subscribed?