Notes

Image Optimization on a Linux server

Edit on GitHub


Linux

jpegoptim

You can do a test run with the -n aka --noaction flag. It will print results without taking any action

jpegoptim -n img/

opencart directories with images

  • image/catalog/
  • catalog/view/
 1#!/bin/bash
 2
 3# optimize-images.sh
 4
 5install() {
 6  # Install tools if not already installed
 7  sudo apt-get install jpegoptim optipng
 8}
 9
10
11optimize_jpeg() {
12  # jpegoptim -pqt --all-progressive *.jpeg
13  
14  # -p, --preserve, Preserve file modification times.
15  # -q, --quiet, Quiet mode.
16  # -t, --totals, Print totals after processing all files.
17  # --all-progressive, Force  all output files to be progressive.
18  
19  find -type f -name "*.jpg" -exec jpegoptim -pqtn --all-progressive {} \;
20}
21
22optimize_png() {
23  find -type f -name "*.png" -exec optipng -simulate -quiet {} \;
24  echo "Optimizing PNGs.. .. "
25}
26
27install
28optimize_jpeg
29optimize_png
30
31echo "Success: Image files have been optimized."