How to compress jpg images in Linux

22,717

You could try mogrify:

https://imagemagick.org/script/mogrify.php

Also see specific examples for image compression:

https://askubuntu.com/questions/25356/decrease-filesize-when-resizing-with-mogrify

mogrify -quality 80 -resize 80 file.jpg

so you should end up with something like

mogrify -quality 80 file.jpg

Test from my machine:

aaron@sandbox:~/img-test$ du -h splash.jpg 
188K    splash.jpg
aaron@sandbox:~/img-test$ mogrify -quality 10 splash.jpg
aaron@sandbox:~/img-test$ du -h splash.jpg 
16K splash.jpg

At 10% this looks terrible, but you get the idea.

You could also use Python's PIL:

https://stackoverflow.com/questions/4353019/in-pythons-pil-how-do-i-change-the-quality-of-an-image

from PIL import Image

im = Image.open("C:\Users\Public\Pictures\Sample Pictures\Jellyfish.jpg") im.save("C:\Users\Public\Pictures\Sample Pictures\Jellyfish_compressed.jpg", quality=10)

Share:
22,717

Related videos on Youtube

hnns
Author by

hnns

Updated on September 18, 2022

Comments

  • hnns
    hnns almost 2 years

    I know that there is 'jpegoptim' to do so. But it not always downsize images as expected. For example if I execute

    jpegoptim --max=50 *.jpg
    

    on a 550KB image, the size will not really reduce. So I am wondering if there are some more efficient tools to do so.

    Thanks