Image optimization
There are several plugins for WordPress that optimize the images uploaded to the media library.
However, performing image optimizations directly on the server instead is often way faster and doesn't add bloat to your WordPress database.
Here's how to perform image optimizations on Templ using SSH.
The first step is to connect to your server using SSH.
The commands below run against your whole wp-content/uploads folder; you can narrow them to a subfolder like wp-content/uploads/2022 to only optimize images uploaded a specific year.
Lossless optimization (recommended)
Lossless means that there will be no difference in terms of perceivable image quality - the optimization is non-visible.
Lossless jpg optimization
To perform a lossless optimization of all jpg images in your uploads folder using jpegoptim, run the following command:
find wp-content/uploads -type f -iname '*.jpg' -exec jpegoptim --strip-all {} +
Lossless png optimization
To perform the equivalent optimization for png images as well, you simply run this command:
find wp-content/uploads -type f -iname '*.png' -exec optipng -strip all {} +
For a more thorough (but still lossless) PNG optimization, raise optipng's optimization effort with the -o flag.
It ranges from 0-7, with 2 as the default; a higher level like -o4 searches harder for a smaller file with no change in image quality, at the cost of speed:
find wp-content/uploads -type f -iname '*.png' -exec optipng -o4 -strip all {} +
Lossy optimization (more aggressive)
If you would like even further reduction in file size, you can instead choose to do a lossy optimization of your jpg images.
The -m80 flag caps JPEG quality at 80, which noticeably reduces file size with minimal visible impact:
find wp-content/uploads -type f -iname '*.jpg' -exec jpegoptim -m80 --strip-all {} +