Mono-repo root for all personal projects
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

31 lines
987 B

#!/bin/bash
file=$1
# Determine extension and destination for each file
# name="${file%.*}";
extension="${file##*.}";
# Start processing
printf "Input | %s\n" "$(du -h "$file")"
# # Compress the file with Tinify API
# # Deprecated in favor of local tools, but useful every now and then for comparisons
# tinify=$(curl --progress-bar --user api:"${TINIFY_API_KEY}" --data-binary @"$file" https://api.tinify.com/shrink)
# tinifyUrl=$(jq '.output.url' <(echo "$tinify") | tr -d '"')
# curl --progress-bar --user api:"${TINIFY_API_KEY}" --output "$file" "$tinifyUrl"
# CWEBP optimizations
cwebp -q 90 -quiet "$file" -o "$file.webp"
# PNG and JPG specific optimizations
if [ "$extension" = "png" ]; then
pngquant --force --strip --output "$file" "$file"
optipng -force -quiet -strip all "$file"
else
jpegoptim --force --quiet --max=90 --strip-all "$file"
fi
# Output results
printf "%s | %s\n" "$extension" "$(du -h "$file")"
printf "webp | %s\n\n" "$(du -h "$file.webp")"