Created
October 12, 2023 07:25
-
-
Save LunarLambda/92477f0faf67009af29f4e0baa999e45 to your computer and use it in GitHub Desktop.
Script for pixel-perfect scaling of Pokémon sprites or other pixel art for use as Discord or Mastodon emotes
This file contains hidden or 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/bash | |
if [ $# -lt 2 ]; then | |
echo "usage: $0 <infile> <outfile>" | |
echo "use TARGET environment variable to set target size (default: 128)" | |
exit 1 | |
fi | |
convert -trim +repage "$1" "$2" | |
read -r w h <<<"$(identify -format '%[fx:w] %[fx:h]' "$2")" | |
size=$(python3 <<EOF | |
d=max($w, $h) | |
print("{0}x{0}".format(d*(${TARGET:-128}//d))) | |
EOF | |
) | |
mogrify -sample "$size" "$2" | |
optipng -quiet "$2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment