读取图像格式并将ascii彩色文本打印到控制台
consoleimages的Python项目详细描述
控制台图像
读取图像格式并将ascii彩色文本打印到控制台
创建image
类的实例,将图像的路径作为参数传递。
实例参数:
-width
(属于astext
字符串)
-height
(属于astext
字符串)
-aspect_ratio
(width
/height
)
-astext
(打印到控制台的字符串)
-name
(图像文件的名称)
-display()
(传递要写入的文件,否则系统标准输出)在
示例:
fromosimportget_terminal_size,listdirfromos.pathimportisfile,joinfromtimeimportsleepfromconsoleimagesimportimagedefclear():fromosimportsystemfromsysimportplatformsystem("cls"ifplatform=="win32"else"clear")# clears the consoleimages={}whileTrue:forimagenamein[fforfinlistdir("images/")ifisfile(join("images/",f))]:# open the 'images/' directory and get all the file names inside.clear()# clear consoleimages[imagename]=image("images/"+imagename,get_terminal_size()[1]-4)# create instance of image classprint(images[imagename].name)# print the name of the image in that instanceimages[imagename].display()# print the imageprint(images[imagename].width,images[imagename].height,sep=" x ",end=" ("+str(images[imagename].aspect_ratio)+")\n")# print the width, height and aspect ratiosleep(2)# wait 2 seconds
- 项目
标签: