Skip to content

Instantly share code, notes, and snippets.

@camilonova
Created October 30, 2019 22:29
Show Gist options
  • Save camilonova/ec7c6ce61dbb80818493e6c976b40158 to your computer and use it in GitHub Desktop.
Save camilonova/ec7c6ce61dbb80818493e6c976b40158 to your computer and use it in GitHub Desktop.
This script creates web files in the current directory
#!/bin/bash
# converting JPEG images
find . -type f -and \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec bash -c '
for result; do
webp_path=$(sed '\''s/\.[^.]*$/.webp/'\'' <<< "$result");
if [ ! -f "$webp_path" ]; then
cwebp "$result" -o "$webp_path";
fi;
done
' _ {} +
# converting PNG images
find . -type f -and -iname "*.png" -exec bash -c '
for result; do
webp_path=$(sed '\''s/\.[^.]*$/.webp/'\'' <<< "$result");
if [ ! -f "$webp_path" ]; then
cwebp -lossless "$result" -o "$webp_path";
fi;
done
' _ {} +
# converting GIF
find . -type f -and -iname "*.gif" -exec bash -c '
for result; do
webp_path=$(sed '\''s/\.[^.]*$/.webp/'\'' <<< "$result");
if [ ! -f "$webp_path" ]; then
gif2webp "$result" -mixed -o "$webp_path";
fi;
done
' _ {} +
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment