How to compress jpg images in Linux

Solution 1:

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)