Skip to content

Instantly share code, notes, and snippets.

@tttimur
Last active May 21, 2021 15:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tttimur/965ac5ff153c5f7b32edcfbfb7d443ce to your computer and use it in GitHub Desktop.
Save tttimur/965ac5ff153c5f7b32edcfbfb7d443ce to your computer and use it in GitHub Desktop.
Image optimization with mozjpeg and webp
# this is not a bash file to execute, but run the following commands in your terminal
# requirements (install instructions at bottom of page)
# imagemin-cli, imagemin-mozjpeg, imagemin-pngquant, imagemin-webp, imagemagick (mogrify)
--------------------------------------------------------------
# 1. create the appropriate directories
$ mkdir build large large-webp small small-webp
# 2. mozjpeg compression of fullsize images
$ imagemin *.jpg --out-dir=build --plugin=mozjpeg && imagemin *.png --out-dir=build --plugin=pngquant
# 3. scale down to 50% in large dir and convert to webp
$ mogrify -path large -resize 50% build/*
$ imagemin ./large/* --out-dir=large-webp --plugin=webp
# 4. scale down to 30% in small dir and convert to webp
$ mogrify -path small -resize 30% build/*
$ imagemin ./small/* --out-dir=small-webp --plugin=webp
--------------------------------------------------------------
# install instructions
$ npm install -g imagemin-cli imagemin-mozjpeg imagemin-webp imagemin-pngquant
$ brew install imagemagick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment