jpegoptim
First install jpegoptim
via
sudo apt install jpegoptim
Then either try to optimize filesize of your image via
jpegoptim /path/to/image.jpg
or if you need a defined size via
jpegoptim --size=512k /path/to/image.jpg
This will overwrite the image - to make sure you have a backup while testing with jpegoptim
.
mogrify (imagemagick)
Resizing
You could as well use mogrify
which is part of imagemagick
. The following example shrinks the image dimensions to 50% (so resizing - not compressing)
mogrify -resize 50% /path/to/image.jpg
Compressing
The following example shows compressing with mogrify
:
mogrify -compress JPEG -quality 50 /path/to/image.jpg
convert (imagemagick)
Compressing
Compressing to 80% using convert works as follows:
convert -quality 80% /path/to/source/image.jpg /path/to/result/image.jpg
Convert somes with a huge set of options, so you could use
convert -strip -interlace Plane -gaussian-blur 0.05 -quality 85% /path/to/source/image.jpg /path/to/result/image.jpg
which should according to this post:
- set the quality to 85
- progressive (comprobed compression)
- a very tiny gausssian blur to optimize the size (0.05 or 0.5 of radius) depends on the quality and size of the picture, this notably optimizes the size of the jpeg.
- Strip any comment or exif tag
trimage
I am quoting the project page here
Trimage is a cross-platform GUI and command-line interface to optimize
image files for websites, using optipng, pngcrush, advpng and
jpegoptim, depending on the filetype (currently, PNG and JPG files are
supported).
You can simply install it via
sudo apt install trimage
After starting via just the application name you might see the UI

If you need more information about trimage either visit the project page or run trimage -h
to take a look on the help.
Other tools
There is as well optipng
, pngcrush
, jpegtran
and several other tools in the image-size-optimization-corner .... but i've never used them.
I'll end with some links
jpegoptim
which is a commandline too to optimize jpegs. In general i would think about either resizing or compressing or a combination of both if your target is reducing filesizejpg
(similar tojpegoptim
). Quote: 'It works by generating many versions of the JPEG image, doing a binary search, of the output quality "-quality" setting, until it gets as close as possible to the file size given without exceeding it' (end quote). Maybe you can write a script that mimicks this behaviour for other formats.