Skip to main content
All CollectionsOptimizations
Image Optimizations
Image Optimizations

How to perform image optimizations directly on the server using jpegoptim and optipng.

Emanuel avatar
Written by Emanuel
Updated over a week ago

There are several plugins for WordPress that optimizes 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.


Lossless optimization (recommended)

Lossless means that there will be no difference in terms of perceivable image quality and the optimization are non-visible.

The first step is to connect to your server using SSH.


Lossless jpg optimization

Then, to perform a lossless optimizations of all jpg images in your 2022 uploads folder using jpegoptim, run the following command:

find wp-content/uploads/2022 -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/2022/ -type f -iname '*.png' -exec optipng -strip all {} +


NOTE: that png optimization is A LOT slower than jpg optimization. We suggest to perform png optimizations at night when there's less traffic on your site.


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 images.


Lossy jpg optimization

If you are willing to accept a 20% quality reduction of your jpg images, you just run this command:

find wp-content/uploads/2022/ -type f -iname '*.jpg' -exec jpegoptim -m80 --strip-all {} +


Lossy png optimization

optipng uses a different quality measurement, ranging from 0-7 and where 2 is used by default.

To perform a slightly more aggressive png optimization, you can for example use quality setting 4 like this:

find wp-content/uploads/2022/ -type f -iname '*.png' -exec optipng -o4 -strip all {} +

Did this answer your question?