Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
362dc5e
commit 458a862
Showing
6 changed files
with
32 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
main() { | ||
declare path="$1" target=${2:-"shrink"} | ||
|
||
mkdir -p "$target" | ||
|
||
find "$path" -type f -iname "*.png" -print0 | while IFS= read -r -d $'\0' image; do | ||
local name=$(basename "$image") | ||
printf "Shrinking \e[36m%s\e[0m... " "$image" | ||
|
||
local target_url=$(curl --user api:$TINYPNG_API_KEY --data-binary @"$image" -s https://api.tinify.com/shrink | jq -r .output.url) | ||
|
||
if [ -z "$target_url" ]; then | ||
echo -e '\e[91m[Error]\e[0m' | ||
continue; | ||
fi | ||
|
||
printf "And saving to \e[93m%s\e[0m... " "$target/$name" | ||
|
||
curl -Ss "$target_url" > "$target/$name" | ||
|
||
printf "\e[92m[Done]\e[0m\n" | ||
done | ||
} | ||
|
||
main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters