I have previously written about how to resize all the images in a folder. That script was based on lossy compression of the files. However, there are also tools for optimizing image files losslessly. One approach is to use the.jpgoptim](https://github.com/tjko.jpgoptim) function available on ubuntu. Here is an excellent explanation of how it works.

Lossless optimization

As part of moving my blog to Hugo, I took the opportunity to optimize all the images in all my image folders. That was done with this one-liner:

find . -name *.jpg -exec.jpgoptim {} \;

I did not calculate the optimization level. However, glancing at the terminal output, it looks like the images have been optimized with 0-10%.

example of optimized files

Fix orientation

While at it, it may also be worth fixing the orientation of files. This can easily be done by running the autorot function:

find . *.jpg -exec jhead -autorot {} \;

It will ensure that the right header is written to the file, which is not always the case coming out of cameras.