Skip to content

Instantly share code, notes, and snippets.

@mertcangokgoz
Created April 28, 2019 10:33
Show Gist options
  • Save mertcangokgoz/8d725b50f5995504944c87d0aab752cb to your computer and use it in GitHub Desktop.
Save mertcangokgoz/8d725b50f5995504944c87d0aab752cb to your computer and use it in GitHub Desktop.
#!/bin/bash
# JPG
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;' {} \;
# PNG
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