Created
August 10, 2013 18:28
-
-
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.
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
#!/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