读取图像格式并将ascii彩色文本打印到控制台

consoleimages的Python项目详细描述


控制台图像

读取图像格式并将ascii彩色文本打印到控制台

创建image类的实例,将图像的路径作为参数传递。 实例参数: -width(属于astext字符串) -height(属于astext字符串) -aspect_ratiowidth/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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java是从此类字符串中提取数据的最佳方法   filenotfoundexception Java FileOutputStream Windows/Linux   java在SQLite数据库Android SDK中搜索特定字符串   java使用键值访问jsp中Map<Long,Map<String,Object>>的内容   java奇怪的HTMLeditor工具包问题   在java中使用数组只计算字母   每个应用程序都可以有自己独立的Java SDK吗   java如何将jasper报告生成的PDF文件保存在一个项目文件夹中   java BigDecimal包装器:静态字段为零   解码Base64图像时出现java IllegalArgumentException(非法的Base64字符)   将int转换为字节在Java和Actionscript中产生不同的结果   java什么使不可变对象在没有安全发布技术的情况下发布?   java将字节数据写入目录   一个计算器中有多个操作的java问题   面向对象Java重写是如何工作的   带hibernate的java ClassCastException   指向最后一个对象的java对象列表   java单元测试spring项目中的Get请求