Skip to content

Instantly share code, notes, and snippets.

@k14i
Created August 10, 2013 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k14i/6201575 to your computer and use it in GitHub Desktop.
Save k14i/6201575 to your computer and use it in GitHub Desktop.
Convert an image file into an ascii art and show it in the terminal. This script requires netpbm.
#!/usr/bin/env bash
if [ $# -ne 1 ]; then
exit 1
fi
filetype=`file -b "$1" | awk '{print $1}'`
if [ x$filetype == x ]; then
msg="ERROR: Could not determine the file type of \"$1\""
echo $msg; logger $msg
exit 1
fi
opt='-contrast 0 -bright 0 -inverse'
case "$filetype" in
'JPEG') jpegtopnm "$1" | aview $opt ;;
'PNG' ) pngtopnm "$1" | aview $opt ;;
* )
anytopnm "$1" | aview $opt
if [ $? -ne 0 ]; then
msg="ERROR: Cannot handle \"$filetype\"."
echo $msg; logger $msg
exit 1
fi
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment