Skip to content

Commit 3d6db8a

Browse files
committed
Merge pull request #5 from bdef/transpng
fix in Ascii.terminal_artify() for when Image.getpixel() returns an int instead of a tuple
2 parents 0a36faa + f749dbd commit 3d6db8a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ascii.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,13 @@ def terminal_artify(self):
128128
for w in range(current_w):
129129
# get brightness value
130130
brightness = grayscale_img.getpixel((w, h))/255.0
131-
srgb = [ (v/255.0)**2.2 for v in canvas.getpixel((w,h)) ]
131+
pixel = canvas.getpixel((w, h))
132+
# getpixel() may return an int, instead of tuple of ints, if the
133+
# source img is a PNG with a transparency layer.
134+
if isinstance(pixel, int):
135+
pixel = (pixel, pixel, 255)
136+
137+
srgb = [ (v/255.0)**2.2 for v in pixel ]
132138

133139
# select required character from the letter_densities list
134140
char_pos = brightness * (len(self.letter_densities) - 1)

0 commit comments

Comments
 (0)