Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
0185d992
Commit
0185d992
authored
11 years ago
by
Eduardo San Martin Morote
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
catimg plugin
allow to print an image to the stdout using convert
parent
357ab491
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
0 deletions
+103
-0
catimg.plugin.zsh
plugins/catimg/catimg.plugin.zsh
+16
-0
catimg.sh
plugins/catimg/catimg.sh
+87
-0
colors.png
plugins/catimg/colors.png
+0
-0
No files found.
plugins/catimg/catimg.plugin.zsh
0 → 100644
View file @
0185d992
################################################################################
# catimg script by Eduardo San Martin Morote aka Posva #
# http://posva.net #
# #
# Ouput the content of an image to the stdout using the 256 colors of the #
# terminal. #
# Github: https://github.com/posva/catimg #
################################################################################
if
[[
-x
`
which convert
`
]]
;
then
function
catimg
()
{
source
$(
dirname
$0
)
/catimg.sh
$@
}
else
echo
"catimg need convert (ImageMagick) to work)"
fi
This diff is collapsed.
Click to expand it.
plugins/catimg/catimg.sh
0 → 100755
View file @
0185d992
################################################################################
# catimg script by Eduardo San Martin Morote aka Posva #
# http://posva.net #
# #
# Ouput the content of an image to the stdout using the 256 colors of the #
# terminal. #
# Github: https://github.com/posva/catimg #
################################################################################
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
${
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
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"
fi
# Display the image
convert
"
$IMG
"
-resize
$COLS
\>
+dither
`
echo
$REMAP
`
txt:- |
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
This diff is collapsed.
Click to expand it.
plugins/catimg/colors.png
0 → 100644
View file @
0185d992
353 Bytes
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment