Skip to content

Instantly share code, notes, and snippets.



Created Sep 13, 2018
What would you like to do?
This simple batch script compresses PNG and JPEG files with TinyPNG API It depends on jq tool
# Usage:
# ./tinypng <path> <path> ...
# Upload the files to shrink and then save them locally under the same name.
# Only works with JPEG and PNG. Accepts wildcard path for batch compression.
# Uses TinyPNG API:
# Uses TINYPNG_API_KEY environment variable for TinyPNG API key.
# Depends on jq:
set -euo pipefail
EMOJIS=("🔥" "⭐️" "❤️" "💯" "👌" "🐝" "💩")
for file in $@ ; do
emoji=${EMOJIS[$RANDOM % ${#EMOJIS[@]} ]}
url=$(curl -sf --user "api:$API_KEY" --data-binary @$file $API_URL | jq -r '.output.url')
curl -sf -o "$file" "$url"
echo "$emoji optimized $file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment