tinypng.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. # fonts color
  3. Green="\033[32m"
  4. Red="\033[31m"
  5. Yellow="\033[33m"
  6. GreenBG="\033[42;37m"
  7. RedBG="\033[41;37m"
  8. Font="\033[0m"
  9. # fonts color
  10. if [ ! -d /pic ]; then
  11. echo -e "${Red}未挂载目录,请重新执行.${Font}"
  12. exit 0
  13. fi
  14. if [ -d /pic/Output ]; then
  15. echo -e "${Red}Output 目录已存在,当前已暂停执行.${Font}"
  16. echo -e "${Red}请将 Output 目录移除或备份至其他目录.${Font}"
  17. echo -e "${Red}否则将会导致重复压缩已输出图片,浪费 API 次数.${Font}"
  18. exit 0
  19. fi
  20. if [ -f /pic/api_key.txt ]; then
  21. sed -i '17d' /tinypng.py
  22. LINE=17
  23. for APIKEY in $(cat /pic/api_key.txt)
  24. do
  25. sed -i "${LINE}i\ \"${APIKEY}\"," /tinypng.py
  26. LINE=$(($LINE+1))
  27. done
  28. fi
  29. python /tinypng.py
  30. if [ ! -f /pic/api_key.txt ]; then
  31. echo -e "${Red}未检测到 api_key.txt${Font}"
  32. echo -e "${Red}已使用内置公开的 key 压缩图片,由于额度有限,图片压缩有可能失败.${Font}"
  33. echo -e "${Green}建议自行免费申请 API key 配置使用更加稳定.${Font}"
  34. fi