Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
malte
chaotikum-logo-20px
Commits
c90b3306
Commit
c90b3306
authored
Aug 31, 2020
by
Malte Schmitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ANSI color printing
parent
19332acf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
0 deletions
+6
-0
foo.py
foo.py
+6
-0
No files found.
foo.py
View file @
c90b3306
...
...
@@ -13,6 +13,10 @@ def encode(a):
result
|=
b
<<
i
*
3
+
2
return
hex
(
result
)
def
ansiColor
(
rgb
):
r
,
g
,
b
=
[
v
*
255
for
v
in
rgb
]
return
"
\033
[48;2;{r};{g};{b}m
\033
[0m"
.
format
(
r
=
r
,
g
=
g
,
b
=
b
)
if
len
(
sys
.
argv
)
!=
2
:
print
(
"Missing file name argument"
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
...
...
@@ -22,6 +26,8 @@ img = Image.open(filename).convert('RGB')
width
,
height
=
img
.
size
pixels
=
[[
mapColors
(
img
.
getpixel
((
x
,
y
)))
for
y
in
range
(
height
)]
for
x
in
range
(
width
)]
print
(
"
\n
"
.
join
([
""
.
join
([
ansiColor
(
v
)
for
v
in
ps
])
for
ps
in
pixels
]))
print
()
array
=
"{"
+
","
.
join
([
encode
(
p
)
for
p
in
pixels
])
+
"}"
...
...
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