A minimal script that converts all jpg/jpeg/png files under a directory to .avif.
Uses find -print0 and read -d '' to handle filenames containing spaces.
#!/usr/bin/env bashset -euo pipefail
while IFS= read -r -d '' file; do avifenc "$file" -o "${file%.*}.avif" >/dev/null 2>&1done < <( find . -type f \( -name '*.jpg' -o -name '*.jpeg' -o -name '*.png' \) -print0)Notes
- If a
.aviffile with the same name already exists, it will be overwritten - To see conversion logs, remove
>/dev/null 2>&1
Practical Note
This snippet fits well when I do not want to rewrite the same operation or check around bash, avifenc, image, conversion, cli over and over. Keeping it as a small helper makes the caller easier to read because the intent stays in the foreground.
If the branches and preconditions start growing, it is usually better not to force everything into one snippet. Splitting the steps and helper responsibilities is easier to maintain.
hsb.horse