Skip to content

Instantly share code, notes, and snippets.

@greghunt
Created November 15, 2022 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greghunt/ace711427d5ea68aece20608e25b34c8 to your computer and use it in GitHub Desktop.
Save greghunt/ace711427d5ea68aece20608e25b34c8 to your computer and use it in GitHub Desktop.
Batch Convert WEBP images
#!/bin/bash
# converting JPEG images
find $1 -type f -and \( -iname "*.jpg" -o -iname "*.jpeg" \) \
-exec bash -c '
webp_path=$(sed 's/\.[^.]*$/.webp/' <<< "$0");
if [ ! -f "$webp_path" ]; then
cwebp -quiet -q 90 "$0" -o "$webp_path";
fi;' {} \;
# converting PNG images
find $1 -type f -and -iname "*.png" \
-exec bash -c '
webp_path=$(sed 's/\.[^.]*$/.webp/' <<< "$0");
if [ ! -f "$webp_path" ]; then
cwebp -quiet -lossless "$0" -o "$webp_path";
fi;' {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment