Skip to content

Instantly share code, notes, and snippets.

@sherlockmac
Forked from tabrindle/webp-convert-directory.sh
Last active August 19, 2022 15:03
Show Gist options
  • Save sherlockmac/78ff13bce4d06771df383f119ea9703c to your computer and use it in GitHub Desktop.
Save sherlockmac/78ff13bce4d06771df383f119ea9703c to your computer and use it in GitHub Desktop.
Convert all files in directory to webp, with default params, or standard cwebp params passed from command
#!/bin/bash
PARAMS=('-m 6 -q 70 -mt -af -progress')
if [ $# -ne 0 ]; then
PARAMS=$@;
fi
cd "$(pwd)"
shopt -s nullglob nocaseglob extglob
for FILE in *.@(jpg|jpeg|tif|tiff|png); do
cwebp $PARAMS "$FILE" -o "${FILE%.*}".webp;
done
@sherlockmac
Copy link
Author

Updated cd $(pwd) to cd "$(pwd)" for folders with space and special characters in their name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment