Created
July 28, 2020 14:24
-
-
Save shitchell/d1e7baf0a22fa9b79128d6170e34c9a8 to your computer and use it in GitHub Desktop.
Use a combination of jp2a and imagemagick to print any image as ascii
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
for path in "$@"; do | |
# Get the mime-type | |
MIMETYPE=$(file --mime-type -b "$path") | |
if [[ "$MIMETYPE" == "image/jpeg" ]]; then | |
# Use jp2a if image is jpg | |
jp2a "$path" | |
elif [[ "$MIMETYPE" =~ image/* ]]; then | |
# Convert image to temporary jpg | |
TMPPATH="/tmp/.$path.jpg" | |
convert "$path" "$TMPPATH" 2>/dev/null | |
# Did conversion fail? | |
if [[ "$?" -ne 0 ]]; then | |
echo "$path: failed to convert image to jpg" | |
fi | |
# Display image | |
jp2a "$TMPPATH" | |
# Delete temporary jpg | |
rm "$TMPPATH" | |
else | |
# Not an image | |
echo "$path: not an image" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment