Skip to content

Instantly share code, notes, and snippets.

@shitchell
Created July 28, 2020 14:24
Show Gist options
  • Save shitchell/d1e7baf0a22fa9b79128d6170e34c9a8 to your computer and use it in GitHub Desktop.
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
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