2024-05-17 14:38:20 发布
网友
我见过一些终端应用程序使用半块来在一个字符块中容纳两种颜色,我想用Python重新创建它,但我不知道如何在Python中实现它,因为我在网上找不到任何关于如何实际实现它的教程/说明。我现在只知道它使用了以下字符:▀ ▄ 但我不知道它是怎么变成一个的,然后转向这个█ 在终点站
从https://github.com/sharkdp/pastel/和https://www.brow.sh/
感谢usr2564301
One color is the foreground – text – color, the other the background color. – usr2564301
这是我的最终代码(使用Pillow和ansicolors模块):
from PIL import Image from colors import color basewidth = 140 img = Image.open(str(input('Input File: '))) wpercent = (basewidth/float(img.size[0])) hsize = int((float(img.size[1])*float(wpercent))) img = img.resize((basewidth,hsize), Image.ANTIALIAS) img = img.convert('RGB') width, height = img.size for i in range(1, height, 2): line = '' for j in range(1, basewidth): ra, ga, ba = img.getpixel((j, i)) rb, gb, bb = img.getpixel((j, i+1)) line += color('\u2584', fg=(rb, gb, bb), bg=(ra, ga, ba)) print(line)
这就是结果:
我可能会将basewidth更改为检查端子宽度,而不是使用固定值
感谢usr2564301
这是我的最终代码(使用Pillow和ansicolors模块):
这就是结果:
我可能会将basewidth更改为检查端子宽度,而不是使用固定值
相关问题 更多 >
编程相关推荐