Created
March 14, 2023 21:34
-
-
Save sod/d5e8941fc46ba7ad07e3f3e826522375 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
EXECUTABLE_WEBP_CHECK=$(brew ls --versions webp) | |
if [[ "" == "${EXECUTABLE_WEBP_CHECK}" ]]; then | |
echo "Error: 'cwebp' missing. Please install via 'brew install webp'" | |
exit 1 | |
fi | |
processFile() { | |
SOURCE="$1" | |
FILENAME=$(basename -- "${SOURCE}") | |
DIR=$(dirname -- "${SOURCE}") | |
FILE="${FILENAME%.*}" | |
( | |
set -x | |
cwebp "${SOURCE}" -o "${DIR}/${FILE}.webp" | |
) | |
} | |
if [ -p /dev/stdin ]; then | |
while IFS= read line; do | |
processFile "${line}" | |
done | |
else | |
if [ -f "$1" ]; then | |
processFile "${1}" | |
else | |
echo "This script creates webp from the source files" | |
echo | |
echo "Usage:" | |
echo | |
echo "Pipe:" | |
echo " find web/images/foo -type f | ../bin/image-generate-webp" | |
echo | |
echo "Argument:" | |
echo " ../bin/image-generate-webp web/images/foo/bar.jpg" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment