Last active
December 21, 2020 13:10
-
-
Save FreeSlave/47d9f83f71feb51b42d8202a85fd0eeb to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
# Generate icons for twitch rewards using imagemagick's or graphicsmagick's convert. | |
# Quantify the image file if it does not fit in 25kb limits. | |
if [ -z "$1" ] | |
then | |
echo "Usage: $0 path-to-image-file" | |
exit 1 | |
fi | |
command_exists() | |
{ | |
command -v "$1" >/dev/null 2>&1 | |
} | |
if command_exists convert | |
then | |
convertcom=convert | |
elif command_exists gm | |
then | |
convertcom="gm convert" | |
fi | |
infile="$1" | |
name="${infile%.*}" | |
for size in 112x112 56x56 28x28 | |
do | |
outfile="$name-$size.png" | |
"$convertcom" -resize $size "$infile" "$outfile" | |
filesize=$(stat --printf="%s" "$outfile") | |
if [ "$filesize" -gt 25600 ] | |
then | |
if command_exists pngquant | |
then | |
echo "resulting image $outfile is too large. Using pngquant" | |
pngquant -f "$outfile" | |
else | |
"$convertcom" -resize $size "$infile" -colors 256 "$outfile" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment