diff options
| author | navewindre <boneyaard@gmail.com> | 2025-07-13 06:42:05 +0200 |
|---|---|---|
| committer | navewindre <boneyaard@gmail.com> | 2025-07-13 06:42:05 +0200 |
| commit | 02f14a9cb152561a5e44062aac79f3b700403b40 (patch) | |
| tree | 2db8ebda3b7f6f8777783aeb5c60018e6e1359d8 /home/.oh-my-zsh/plugins/catimg | |
| parent | cbbdeb2f6b40a102a829f0c47cff052937231f00 (diff) | |
omz
Diffstat (limited to 'home/.oh-my-zsh/plugins/catimg')
| -rw-r--r-- | home/.oh-my-zsh/plugins/catimg/README.md | 24 | ||||
| -rw-r--r-- | home/.oh-my-zsh/plugins/catimg/catimg.plugin.zsh | 19 | ||||
| -rw-r--r-- | home/.oh-my-zsh/plugins/catimg/catimg.sh | 92 | ||||
| -rw-r--r-- | home/.oh-my-zsh/plugins/catimg/colors.png | bin | 0 -> 353 bytes |
4 files changed, 135 insertions, 0 deletions
diff --git a/home/.oh-my-zsh/plugins/catimg/README.md b/home/.oh-my-zsh/plugins/catimg/README.md new file mode 100644 index 0000000..4cfda0e --- /dev/null +++ b/home/.oh-my-zsh/plugins/catimg/README.md @@ -0,0 +1,24 @@ +# catimg + +Plugin for displaying images on the terminal using the `catimg.sh` script provided by +[posva](https://github.com/posva/catimg) + +To use it, add `catimg` to the plugins array in your zshrc file: + +```zsh +plugins=(... catimg) +``` + +## Requirements + +- `magick convert` (ImageMagick) + +## Functions + +| Function | Description | +| -------- | ---------------------------------------- | +| `catimg` | Displays the given image on the terminal | + +## Usage examples + +[](https://asciinema.org/a/204702) diff --git a/home/.oh-my-zsh/plugins/catimg/catimg.plugin.zsh b/home/.oh-my-zsh/plugins/catimg/catimg.plugin.zsh new file mode 100644 index 0000000..ad10d85 --- /dev/null +++ b/home/.oh-my-zsh/plugins/catimg/catimg.plugin.zsh @@ -0,0 +1,19 @@ +################################################################################ +# catimg script by Eduardo San Martin Morote aka Posva # +# https://posva.net # +# # +# Output the content of an image to the stdout using the 256 colors of the # +# terminal. # +# GitHub: https://github.com/posva/catimg # +################################################################################ + + +function catimg() { + if (( $+commands[magick] )); then + CONVERT_CMD="magick" zsh $ZSH/plugins/catimg/catimg.sh $@ + elif (( $+commands[convert] )); then + CONVERT_CMD="convert" zsh $ZSH/plugins/catimg/catimg.sh $@ + else + echo "catimg need magick/convert (ImageMagick) to work)" + fi +} diff --git a/home/.oh-my-zsh/plugins/catimg/catimg.sh b/home/.oh-my-zsh/plugins/catimg/catimg.sh new file mode 100644 index 0000000..7946ad1 --- /dev/null +++ b/home/.oh-my-zsh/plugins/catimg/catimg.sh @@ -0,0 +1,92 @@ +################################################################################ +# catimg script by Eduardo San Martin Morote aka Posva # +# https://posva.net # +# # +# Output the content of an image to the stdout using the 256 colors of the # +# terminal. # +# GitHub: https://github.com/posva/catimg # +################################################################################ + +# this should come from outside, either `magick` or `convert` +# from imagemagick v7 and ahead `convert` is deprecated +: ${CONVERT_CMD:=convert} + +function help() { + echo "Usage catimg [-h] [-w width] [-c char] img" + echo "By default char is \" \" and w is the terminal width" +} + +# VARIABLES +COLOR_FILE=$(dirname $0)/colors.png +CHAR=" " + +WIDTH="" +IMG="" + +while getopts qw:c:h opt; do + case "$opt" in + w) WIDTH="$OPTARG" ;; + c) CHAR="$OPTARG" ;; + h) help; exit ;; + *) help ; exit 1;; + esac + done + +while [ "$1" ]; do + IMG="$1" + shift +done + +if [ "$IMG" = "" -o ! -f "$IMG" ]; then + help + exit 1 +fi + +if [ ! "$WIDTH" ]; then + COLS=$(expr $(tput cols) "/" $(echo -n "$CHAR" | wc -c)) +else + COLS=$(expr $WIDTH "/" $(echo -n "$CHAR" | wc -c)) +fi +WIDTH=$($CONVERT_CMD "$IMG" -print "%w\n" /dev/null) +if [ "$WIDTH" -gt "$COLS" ]; then + WIDTH=$COLS +fi + +REMAP="" +if $CONVERT_CMD "$IMG" -resize $COLS\> +dither -remap $COLOR_FILE /dev/null ; then + REMAP="-remap $COLOR_FILE" +else + echo "The version of convert is too old, don't expect good results :(" >&2 + # $CONVERT_CMD "$IMG" -colors 256 PNG8:tmp.png + # IMG="tmp.png" +fi + +# Display the image +I=0 +$CONVERT_CMD "$IMG" -resize $COLS\> +dither `echo $REMAP` txt:- 2>/dev/null | +sed -e 's/.*none.*/NO NO NO/g' -e '1d;s/^.*(\(.*\)[,)].*$/\1/g;y/,/ /' | +while read R G B f; do + if [ ! "$R" = "NO" ]; then + if [ "$R" -eq "$G" -a "$G" -eq "$B" ]; then + (( + I++, + IDX = 232 + R * 23 / 255 + )) + else + (( + I++, + IDX = 16 + + R * 5 / 255 * 36 + + G * 5 / 255 * 6 + + B * 5 / 255 + )) + fi + #echo "$R,$G,$B: $IDX" + echo -ne "\e[48;5;${IDX}m${CHAR}" + else + (( I++ )) + echo -ne "\e[0m${CHAR}" + fi + # New lines + (( $I % $WIDTH )) || echo -e "\e[0m" +done diff --git a/home/.oh-my-zsh/plugins/catimg/colors.png b/home/.oh-my-zsh/plugins/catimg/colors.png Binary files differnew file mode 100644 index 0000000..5f2c812 --- /dev/null +++ b/home/.oh-my-zsh/plugins/catimg/colors.png |
