ADD tiny_recursive
This commit is contained in:
parent
ce01edc044
commit
acf4d55220
|
|
@ -1,4 +1,6 @@
|
|||
# Скрипты для настройки Linux окружения
|
||||
|
||||
## Скрипты
|
||||
`updgit` -- рекурсивное обновление git репозиториев в папке до актуальных коммитов
|
||||
`updgit` -- рекурсивное обновление git репозиториев в папке до актуальных коммитов
|
||||
|
||||
`tiny_recursive` -- рекурсивная оптимизация JPG и PNG изображений в папках, через сервис tinypng
|
||||
|
|
|
|||
38
scripts/tiny_recursive.sh
Normal file
38
scripts/tiny_recursive.sh
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#!/bin/bash
|
||||
# Install
|
||||
# This script need a API key from TinyPNG. See this page: https://tinypng.com/developers
|
||||
# It also need jq library, which can be install thanks to: `brew install jq`
|
||||
|
||||
# Usage
|
||||
# cd to your folder. This script will compress all PNG or JPG files recursively.
|
||||
|
||||
API_KEY="r9CMpg9PZSdWKf5Y0s4YSyb5y99DL2zp"
|
||||
RED="\033[0;31m"
|
||||
GREEN="\033[0;32m"
|
||||
NORMAL="\033[0m"
|
||||
|
||||
if [ $API_KEY = "CHANGE THE API_KEY" ]
|
||||
then
|
||||
echo "YES. CHANGE THE API_KEY in this file."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! type "jq" > /dev/null
|
||||
then
|
||||
echo "Please install `jq`"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
find . -type f \( -name \*.jpg -o -name \*.png -o -name \*.jpeg \) -print0 | while IFS= read -r -d '' file; do
|
||||
echo "Compress file: $file"
|
||||
|
||||
json=$(curl -sS --user api:$API_KEY --data-binary @"$file" https://api.tinypng.com/shrink)
|
||||
url=$(jq -n "$json.output.url" | sed -e 's/^"//' -e 's/"$//')
|
||||
|
||||
echo -e "Compression OK. Old size: $(jq -n "$json.input.size"), new size: $(jq -n "$json.output.size"), ratio: ${GREEN} $(jq -n "$json.output.ratio")${NORMAL}"
|
||||
echo "Downloading the compressed file…"
|
||||
|
||||
curl -sS $url > "$file"
|
||||
|
||||
echo "Compressed file downloaded with success!"
|
||||
done
|
||||
Loading…
Reference in New Issue
Block a user