summaryrefslogtreecommitdiff
path: root/plugins/catimg
diff options
context:
space:
mode:
authorGentoo <43550690+maxutka99@users.noreply.github.com>2024-08-12 12:46:16 +0300
committerGitHub <noreply@github.com>2024-08-12 11:46:16 +0200
commitd6f84f3e7d2515cee8ba776d05ee2009ffd471d7 (patch)
tree8e9406f25ea250d0a1644f8762973b329166bfa9 /plugins/catimg
parent47767bd03cae60bc4b3d8ab4ba8e6b6c78bc17ed (diff)
downloadzsh-d6f84f3e7d2515cee8ba776d05ee2009ffd471d7.tar.gz
zsh-d6f84f3e7d2515cee8ba776d05ee2009ffd471d7.tar.bz2
zsh-d6f84f3e7d2515cee8ba776d05ee2009ffd471d7.zip
fix(catimg): add support to `magick` binary (#12608)
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
Diffstat (limited to 'plugins/catimg')
-rw-r--r--plugins/catimg/README.md5
-rw-r--r--plugins/catimg/catimg.plugin.zsh8
-rw-r--r--plugins/catimg/catimg.sh14
3 files changed, 17 insertions, 10 deletions
diff --git a/plugins/catimg/README.md b/plugins/catimg/README.md
index 68dc33c1f..4cfda0e25 100644
--- a/plugins/catimg/README.md
+++ b/plugins/catimg/README.md
@@ -1,6 +1,7 @@
# catimg
-Plugin for displaying images on the terminal using the `catimg.sh` script provided by [posva](https://github.com/posva/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:
@@ -10,7 +11,7 @@ plugins=(... catimg)
## Requirements
-- `convert` (ImageMagick)
+- `magick convert` (ImageMagick)
## Functions
diff --git a/plugins/catimg/catimg.plugin.zsh b/plugins/catimg/catimg.plugin.zsh
index f4ff6f856..ad10d8574 100644
--- a/plugins/catimg/catimg.plugin.zsh
+++ b/plugins/catimg/catimg.plugin.zsh
@@ -9,9 +9,11 @@
function catimg() {
- if [[ -x `which convert` ]]; then
- zsh $ZSH/plugins/catimg/catimg.sh $@
+ 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 convert (ImageMagick) to work)"
+ echo "catimg need magick/convert (ImageMagick) to work)"
fi
}
diff --git a/plugins/catimg/catimg.sh b/plugins/catimg/catimg.sh
index f58392428..7946ad16e 100644
--- a/plugins/catimg/catimg.sh
+++ b/plugins/catimg/catimg.sh
@@ -7,6 +7,10 @@
# 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"
@@ -43,23 +47,23 @@ if [ ! "$WIDTH" ]; then
else
COLS=$(expr $WIDTH "/" $(echo -n "$CHAR" | wc -c))
fi
-WIDTH=$(convert "$IMG" -print "%w\n" /dev/null)
+WIDTH=$($CONVERT_CMD "$IMG" -print "%w\n" /dev/null)
if [ "$WIDTH" -gt "$COLS" ]; then
WIDTH=$COLS
fi
REMAP=""
-if convert "$IMG" -resize $COLS\> +dither -remap $COLOR_FILE /dev/null ; then
+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 "$IMG" -colors 256 PNG8:tmp.png
- #IMG="tmp.png"
+ # $CONVERT_CMD "$IMG" -colors 256 PNG8:tmp.png
+ # IMG="tmp.png"
fi
# Display the image
I=0
-convert "$IMG" -resize $COLS\> +dither `echo $REMAP` txt:- 2>/dev/null |
+$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