convert_to_webp.sh 814 B

1234567891011121314151617181920
  1. #! /bin/sh
  2. read -p "Continue (y/n)? " choice
  3. case "$choice" in
  4. y|Y ) echo "yes" ;;
  5. n|N ) echo "no" && exit 0 ;;
  6. * ) echo "invalid" && exit 1 ;;
  7. esac
  8. # Convert all the PNG and JPEG files to WebP format with 75 quality lossy compression
  9. # Then delete all the unused JPEG/PNG files
  10. find ./ -type f -name '*.png' -exec sh -c 'cwebp -q 80 $1 -o "${1%.png}.webp" && rm "${1}"' _ {} \;
  11. find ./ -type f -name '*.jpg' -exec sh -c 'cwebp -q 80 $1 -o "${1%.jpg}.webp" && rm "${1}"' _ {} \;
  12. find ./ -type f -name '*.jpeg' -exec sh -c 'cwebp -q 80 $1 -o "${1%.jpeg}.webp" && rm "${1}"' _ {} \;
  13. find ./ -type f -name '*.gif' -exec sh -c 'cwebp -q 80 $1 -o "${1%.gif}.webp" && rm "${1}"' _ {} \;
  14. # find ./ -type f -name '*.jpg' -delete ;
  15. # find ./ -type f -name '*.jpeg' -delete ;
  16. # find ./ -type f -name '*.png' -delete ;