Created
October 6, 2015 19:05
-
-
Save wallentx/d0bb89a6d42f5b5afbd4 to your computer and use it in GitHub Desktop.
convert small images like sprites to terminal ready ascii art. Not mine. I forgot where i downloaded it from.
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/bash | |
if [ $# -eq 0 ]; then | |
echo -e " \n \t ERROR: No arguments provided" | |
echo -e " \t USAGE: img2sf <path/to/image> <path/to/output>\n" | |
exit 1 | |
fi | |
imgw=$(convert -print "%w\n" "$1" /dev/null) | |
# generate the image | |
TMPFILE="tmp" | |
img2xterm "$1" > $TMPFILE | |
# form the output file | |
#echo 'startline="0"' > $2 | |
#echo 'fulloutput=(' >> $2 | |
IFS='' | |
cat $TMPFILE | | |
while read line | |
do | |
nspaces=$(grep -o " " <<< "$line" | wc -l) | |
nup=$(grep -o "▀" <<< "$line" | wc -l) | |
ndown=$(grep -o "▄" <<< "$line" | wc -l) | |
spaces=$(expr "$imgw" - "$nspaces" - "$nup" - "$ndown") | |
# printf "\"%s%${spaces}s %%s\"\n" "$line" "" >> $2 | |
printf "%s%${spaces}s \\n" "$line" >> $2 | |
done | |
#echo ")" >> $2 | |
sed -i "0,/%s/{s/%s/ %s/}" "$2" | |
# clean up | |
rm $TMPFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment