A basic shell script to find the number of pixels out of the hex in unit images

This commit is contained in:
Ali El Gariani 2009-03-27 18:19:56 +00:00
parent f27228dfd0
commit aa6cc76240
2 changed files with 136 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 B

136
data/tools/hexometer/hexometer Executable file
View file

@ -0,0 +1,136 @@
#!/bin/sh
scriptname="hexometer"
help ()
{
echo "Search png images not fitting in a hex"
echo
echo "$scriptname [option] [directory1 directory2 ...]"
echo "-m, --mask file choose which image use as mask"
echo " (default = alphamask.png)"
echo "-a, --anim skip most animations images (containing:"
echo " -attack -defend -melee -ranged -magic -idle"
echo " -die -dying -death -healing -flying -leading)"
echo "-s, --suffix skip images with directional or numerical suffix"
echo "-r, --regex REG skip images matching the case-insensitive"
echo " regular expression REG (posix-extended)"
echo "-f, --format skip images which are not in 72x72 format"
echo "-q, --quiet only display results"
echo
echo "return numbers of pixels out of the hex for each filename"
echo "(-1 if the image is not a standard 72x72 image and -f was not used"
}
mask="alphamask.png"
format=0
quiet=0
regex=""
suffix=".*(-n|-s|-w|-e|-ne|-nw|-sw|-se|-[0-9]+)(-|[.]).*"
anim=".*-attack.*|.*-defend.*|.*-melee.*|.*-ranged.*|.*-magic.*|.*-idle.*|.*-die.*|.*-dying.*|.*-death.*|.*-flying.*|.*-leading.*|.*-healing.*"
until [ -z "$1" ]
do
if [ "$1" == "--help" -o "$1" == "-h" ]
then
help
exit
fi
if [ "$1" == "--mask" -o "$1" == "-m" ]
then
shift
mask="$1"
shift
continue
fi
if [ "$1" == "--regex" -o "$1" == "-r" ]
then
shift
regex="$regex|$1"
shift
continue
fi
if [ "$1" == "--anim" -o "$1" == "-a" ]
then
regex="$regex|$anim"
shift
continue
fi
if [ "$1" == "--suffix" -o "$1" == "-s" ]
then
regex="$regex|$suffix"
shift
continue
fi
if [ "$1" == "--format" -o "$1" == "-f" ]
then
format=1
shift
continue
fi
if [ "$1" == "--quiet" -o "$1" == "-q" ]
then
quiet=1
shift
continue
fi
# record all given directories
dir="$dir $1"
shift
done
# if no directory, use current
if [ "$dir" == "" ]
then
dir='.'
fi
if [ ! -r $mask ]
then
echo "$scriptname : cannot access $mask : No such file or directory "
exit 1
fi
if [ "$quiet" == 0 ]
then
echo "Search 72x72 images not fitting in a hex"
echo "in directories : $dir"
echo "Using alphamask image : $mask"
echo "Skipping files matching regex: $regex"
echo "Pixels out of hex : filename"
fi
test_img()
{
if [ `identify -format "%wx%h" $img` != '72x72' ]
then
if [ $format == 0 ]
then
px=-1
else
# mark as ok, because user want to skip bad format
px=0
fi
else
px=`composite $mask $img /tmp/tmp_result.png && compare -channel alpha -metric AE $mask /tmp/tmp_result.png /dev/null 2>&1 `
fi
if [ "$px" != 0 ]
then
echo -e "$px\t : $img"
fi
}
find $dir -regextype posix-extended -name '*.png' -and -not -iregex "$regex" \
-print | sort | while read img; do test_img; done
rm -f /tmp/tmp_result.png
exit