Skip to content

Instantly share code, notes, and snippets.

@sheanhoxie
Last active March 24, 2023 18:30
Show Gist options
  • Save sheanhoxie/21dada66ab3e6324adb871445fb49fdc to your computer and use it in GitHub Desktop.
Save sheanhoxie/21dada66ab3e6324adb871445fb49fdc to your computer and use it in GitHub Desktop.
script to convert all images in a directory to webp, on mac osx
// Install webp via Brew
brew install webp
cwebp [-preset <...>] [options] in_file [-o out_file]
options:
-o outfile
-q <float> quality 0-100
-alpha_q <int> transparency compression 0-100
-preset <string> default, photo, picture, drawing, icon, text
-preset must come first
-m compression (0=fast, 6=slow), default=4
-size <int> target size (in bytes)
// Convert jpg to webp
for F in *.jpg; do cwebp -q 51 -m 5 $F -o `basename ${F%.jpg}`.webp; done
// Convert png to webp
for F in *.png; do cwebp $F -o `basename ${F%.png}`.webp; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment