Skip to content

Instantly share code, notes, and snippets.

@oguz-ismail
Last active November 25, 2022 11:43
Show Gist options
  • Save oguz-ismail/c3da5aec9b3ea4d4fbd4255ba27a5335 to your computer and use it in GitHub Desktop.
Save oguz-ismail/c3da5aec9b3ea4d4fbd4255ba27a5335 to your computer and use it in GitHub Desktop.
convert all WEBP to PNG/JPG
# nowebp - find and convert WEBP images
#
# Usage: nowebp [DIR]
#
# nowebp searches the directory hierarchy starting from DIR (current
# directory if absent) for images in WEBP format, and converts each
# image it finds to PNG or JPG, depending on whether it is compressed
# losslessly or contains transparent pixels, or neither, respectively.
export LC_ALL=C
find "${1-.}" \
-type f \( -name '*.webp' -o -name '*.jpg' -o -name '*.png' \) \
-exec sh -c '
for src; do
case $(head -c 42 "$src" | tr -c A-Z0-9 x) in
RIFF????WEBPVP8X??????????????ANIM* | RIFF????WEBPVP8X??????????????ICCP????ANIM)
printf "%s: animated WEBP not supported\n" "$src" >&2
continue ;;
RIFF????WEBPVP8L* | RIFF????WEBPVP8X??????????????ALPH*)
fmt=png ;;
RIFF????WEBPVP8*)
fmt=jpg ;;
*)
continue
esac
dest=$src.$fmt
ffmpeg -loglevel error -i "$src" "$dest" &&
rm -i "$src"
done' sh {} +
# vi: ft=sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment