This module contains code that converts image data to formats suitable for printing to console.
More...
This module contains code that converts image data to formats suitable for printing to console.
Based on https://github.com/hit9/img2txt by @hit9 with minor modifications, BSD license as follows:
◆ _alpha_blend()
def image_console_printer._alpha_blend |
( |
|
src, |
|
|
|
dst |
|
) |
| |
|
private |
40 src_multiplier = (src[3] / 255.0)
41 dst_multiplier = (dst[3] / 255.0) * (1 - src_multiplier)
42 result_alpha = src_multiplier + dst_multiplier
47 int(((src[0] * src_multiplier) + (dst[0] * dst_multiplier)) / result_alpha),
48 int(((src[1] * src_multiplier) + (dst[1] * dst_multiplier)) / result_alpha),
49 int(((src[2] * src_multiplier) + (dst[2] * dst_multiplier)) / result_alpha),
50 int(result_alpha * 255)
◆ _generate_grayscale_for_image()
def image_console_printer._generate_grayscale_for_image |
( |
|
pixels, |
|
|
|
width, |
|
|
|
height, |
|
|
|
bgcolor |
|
) |
| |
|
private |
56 color =
"MNHQ$OC?7>!:-;. "
60 for h
in range(height):
61 for w
in range(width):
67 if rgba[3] != 255
and bgcolor
is not None:
76 string += color[int(sum(rgb) / 3.0 / 256.0 * 16)]
◆ print_image_to_console()
def image_console_printer.print_image_to_console |
( |
|
img | ) |
|
83 if img.mode !=
'RGBA':
84 img = img.convert(
'RGBA')
86 fill_string =
"\x1b[49m"
87 fill_string +=
"\x1b[K"
88 sys.stdout.write(fill_string)
96 sys.stdout.write(
"\x1b[0m\n")