Images were taking too long to load in the galleries, and I gave up using an external service to generate and cache the thumbnail images. This is a bit of a semi-manual solution which could reasonably be automated but probably won’t be.

For generation of thumbnails:

mogrify -gravity center -crop 1:1 -thumbnail 256x256 *

This generates a 256x256 image that’s pretty small for use as a thumbnail.

Affects all images in the folder in which it is run.

For optimisation of images:

mogrify -scale 40% -quality 86 -strip *

This strips metadata, scales it by 40%, and reduces the image quality to 86%.

This gives perfectly adequately image files with a nice compromise between detail and file size.

Affects all images in the folder in which it is run.

Performance

Taking an original image of size 5.4 MB produced a final image of 588 KB with a 39 KB thumbnail.

The -strip argument saves around 40 KB. -thumbnail automagically uses the -strip argument for you.

Note that mogrify overwrites the original files so I duplicate between image and thumbnail directories first, then run relevant command in each folder.

I must note here that it has a strange habit of rotating some images if they were originally taken portrait. No easy solution known at this time.

Examples

mogrify -scale 75% -quality 90 -verbose *.jpg

Also Handy

Rename to be the creation date

jhead -n%Y%m%d-%H%M%S *.JPG
mogrify -scale 75% -quality 90 -verbose *.jpg

With 18 <= crf <= 24. Higher = lower bitrate:

ffmpeg -i input.mp4 -vcodec libx264 -crf 24 output.mp4
ffmpeg -i input.mp4 -b 800k output.mp4