Transform All Image Files to webp
Bash script that replaces all image files within a folder into webp files of the same size.
assuming there is a folder uploads
in the current working directory, that contains image files that need to be transcoded to webp:
find ./uploads -type f ! -name "*.webp" -exec bash -c '
FILE="$1"
BASE="${FILE%.*}"
EXT="${FILE##*.}"
BASE="${FILE%.$EXT}"
WEBP="$BASE.webp"
cwebp -q 80 "$FILE" -o "$WEBP"
rm "$FILE"
' bash {} \;
note that the script skips already existing webp files and also checks to handle file names with multiple dots in them.
to get the cwebp
tool on Mac OS, simply run brew install webp
Linked Technologies
What it's made of
Shell
Shell scripting: Automate and streamline your tasks with powerful command-line scripts. Unlock efficiency in every command! Contains bash, zsh, sh, ...
Linked Categories
Where it's useful
Data Engineering
Explore the essentials of Data Engineering, delving into how data systems are built and maintained. From organizing data flows to automating complex data processes, discover the tools and techniques that make data easily accessible and useful for everyday projects and insights.
System Administration
Explore the critical world of System Administration, where efficiency and reliability keep computer systems running smoothly. Learn about the tools and techniques for managing servers, networks, and software to ensure optimal performance and security.