Created
June 7, 2015 00:26
-
-
Save thewestwind/fff3de4c5f53974468ef to your computer and use it in GitHub Desktop.
Some alpha-aware resizing script based on netpbm
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
#!/usr/bin/env bash | |
function usage() { | |
echo "USAGE: $0 < input.png > output.png" 1>&2 | |
echo "USAGE: env gif=1 $0 < input.gif > output.png" 1>&2 | |
exit -1 | |
} | |
if tty < /dev/stdin >&/dev/null; then | |
usage | |
fi | |
if tty < /dev/stdout >&/dev/null; then | |
usage | |
fi | |
set -e | |
image="$(mktemp /tmp/png_original_XXXXXX)" | |
alpha="$(mktemp /tmp/png_alpha_XXXXXX)" | |
alpha_2="$(mktemp /tmp/png_alpha_XXXXXX)" | |
bitmap="$(mktemp /tmp/png_bitmap_XXXXXX)" | |
trap "rm -f $image $alpha $alpha_2 $bitmap" EXIT | |
cat > $image | |
function intermediate { | |
pamscale -linear -xysize 1500 1500 | |
} | |
command="pngtopnm" | |
if [ ! "$gif" = "" ]; then | |
set -x | |
giftopnm -alpha=$alpha_2 < $image >/dev/null | |
intermediate < $alpha_2 > $alpha | |
command=giftopnm | |
else | |
pngtopnm -alpha < $image | intermediate > $alpha | |
fi | |
$command < $image | intermediate > $bitmap | |
pnmtopng -compress 9 -filter 0 -force -alpha=$alpha < $bitmap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment