Skip to content

Instantly share code, notes, and snippets.

@FreeSlave
Last active December 21, 2020 13:10
Show Gist options
  • Save FreeSlave/47d9f83f71feb51b42d8202a85fd0eeb to your computer and use it in GitHub Desktop.
Save FreeSlave/47d9f83f71feb51b42d8202a85fd0eeb to your computer and use it in GitHub Desktop.
#!/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