@@ -44,17 +44,18 @@ function encodeimg{C<:Colorant}(
44
44
maxwidth:: Int = 80 )
45
45
maxheight = max (maxheight, 5 )
46
46
maxwidth = max (maxwidth, 5 )
47
- h, w = size ( img)
47
+ h, w = map (length, indices ( img) )
48
48
while ceil (h/ 2 ) > maxheight || w > maxwidth
49
49
img = restrict (img)
50
- h, w = size ( img)
50
+ h, w = map (length, indices ( img) )
51
51
end
52
+ yinds, xinds = indices (img)
52
53
io = IOBuffer ()
53
- for y in 1 : 2 : h
54
+ for y in first (yinds) : 2 : last (yinds)
54
55
print (io, Crayon (reset = true ))
55
- for x in 1 : w
56
+ for x in xinds
56
57
fgcol = _colorant2ansi (img[y,x], colordepth)
57
- bgcol = if y+ 1 <= h
58
+ bgcol = if y+ 1 <= last (yinds)
58
59
_colorant2ansi (img[y+ 1 ,x], colordepth)
59
60
else
60
61
# if reached it means that the last character row
@@ -76,15 +77,16 @@ function encodeimg{C<:Colorant}(
76
77
maxwidth:: Int = 80 )
77
78
maxheight = max (maxheight, 5 )
78
79
maxwidth = max (maxwidth, 5 )
79
- h, w = size ( img)
80
+ h, w = map (length, indices ( img) )
80
81
while h > maxheight || 2 w > maxwidth
81
82
img = restrict (img)
82
- h, w = size ( img)
83
+ h, w = map (length, indices ( img) )
83
84
end
85
+ yinds, xinds = indices (img)
84
86
io = IOBuffer ()
85
- for y in 1 : h
87
+ for y in yinds
86
88
print (io, Crayon (reset = true ))
87
- for x in 1 : w
89
+ for x in xinds
88
90
color = img[y,x]
89
91
fgcol = _colorant2ansi (color, colordepth)
90
92
chr = _charof (alpha (color))
@@ -102,14 +104,14 @@ function encodeimg{C<:Colorant}(
102
104
img:: AbstractVector{C} ,
103
105
maxwidth:: Int = 80 )
104
106
maxwidth = max (maxwidth, 5 )
105
- w = length (img)
107
+ w = length (indices ( img, 1 ) )
106
108
if w > maxwidth
107
109
img = imresize (img, maxwidth)
108
- w = length (img)
110
+ w = length (indices ( img, 1 ) )
109
111
end
110
112
io = IOBuffer ()
111
113
print (io, Crayon (reset = true ))
112
- for i in 1 : w
114
+ for i in indices (img, 1 )
113
115
color = img[i]
114
116
fgcol = _colorant2ansi (color, colordepth)
115
117
chr = _charof (alpha (color))
@@ -125,19 +127,20 @@ function encodeimg{C<:Colorant}(
125
127
img:: AbstractVector{C} ,
126
128
maxwidth:: Int = 80 )
127
129
maxwidth = max (maxwidth, 5 )
128
- w = length (img)
130
+ inds = indices (img, 1 )
131
+ w = length (inds)
129
132
n = 3 w > maxwidth ? floor (Int,maxwidth/ 6 ) : w
130
133
io = IOBuffer ()
131
134
print (io, Crayon (reset = true ))
132
- for i in 1 : n
135
+ for i in ( 0 : n - 1 ) + first (inds)
133
136
color = img[i]
134
137
fgcol = _colorant2ansi (color, colordepth)
135
138
chr = _charof (alpha (color))
136
139
print (io, Crayon (foreground = fgcol), chr, chr, " " )
137
140
end
138
141
if n < w
139
142
print (io, Crayon (reset = true ), " … " )
140
- for i in w - n+ 1 : w
143
+ for i in last (inds) - n+ 1 : last (inds)
141
144
color = img[i]
142
145
fgcol = _colorant2ansi (color, colordepth)
143
146
chr = _charof (alpha (color))
@@ -147,4 +150,3 @@ function encodeimg{C<:Colorant}(
147
150
println (io, Crayon (reset = true ))
148
151
replace .(readlines (seek (io,0 )), [" \n " ], [" " ]):: Vector{String} , 1 , n < w ? 3 * (length (1 : n) + 1 + length (w- n+ 1 : w)) : 3 w
149
152
end
150
-
0 commit comments