1 2 3 4 5 6 7 8 ██╗ ██╗ ██╗██╗ ██╗ ██████╗ ███████╗███████╗████████╗ ██║ ╚██╗ ██╔╝██║ ██║ ██╔══██╗██╔════╝██╔════╝╚══██╔══╝ ██║ ╚████╔╝ ███████║ ██████╔╝█████╗ ███████╗ ██║ ██║ ╚██╔╝ ██╔══██║ ██╔══██╗██╔══╝ ╚════██║ ██║ ███████╗██║ ██║ ██║██╗██████╔╝███████╗███████║ ██║ ╚══════╝╚═╝ ╚═╝ ╚═╝╚═╝╚═════╝ ╚══════╝╚══════╝ ╚═╝
ASCII Art 能够帮助我们通过电脑字符来表达图片、文本,甚至是流程图。
1️⃣ fun-comment
GitHub | VSCode
这是一款面向 VSCode 的内置插件,通过 fun-comment,你可以上传静态图片或者选择文字,将它们转换为 ASCII art 字符画。可作注释用途,也可以分享给他人
2️⃣ Patorjk官网 这是一个通过文本生成 ASCII art 字符画的在线网站,其中提供了包含字体、宽度、高度等在内的多个自定义选项。输入你想要转换的文本,点击「Test All」,在众多样式中找到你中意的那一个 同时作者还有另外一个ascii图形生成器:http://patorjk.com/arial-ascii-art
3️⃣ char-dust
GitHub | Web
Features:
4️⃣ 命令行工具figlet
1 2 3 4 figlet [ -cklnoprstvxDELNRSWX ] [ -d fontdirectory ] [ -f fontfile ] [ -m layoutmode ] [ -w outputwidth ] [ -C controlfile ] [ -I infocode ] [ message ]
安转后直接在命令行中使用即可。更多高级用法参考figlet-man
更多字符画生成器 ascii-art-generator IMG2TXT Ascii.mastervb GlassGiant ASCII Art ASCII码艺术(字符图像)在线生成器
Python 实现 video2char 1 2 3 4 5 6 { "width" : 135 , "height" : 240 , "charset" : "$@B%8&WM#*oahkbdpqwmzcvunxrjft/\\|()1{}[]?-_+~<>i!;:,\"^`'. " , "file" : "c://Users/0/Desktop/python/goodluck.mp4" }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 import osimport jsonfrom PIL import Imageimport webbrowserSTYLE = '<style>pre{font-size: 10px;line-height: 7px;}</style>\r\n' CHAR_TEMP = '<pre style="display:none">\r\n%s</pre>' JAVASCRIPT = '''<script> var body; var first; var init = function() { body = document.getElementsByTagName("body")[0]; first = body.firstChild; } var doframe = function() { body.removeChild(first); first = body.firstChild; first.style.display = 'block'; } setTimeout(init, 1); setInterval(doframe, 100); </script>''' def charset256 (charset ): charset_len = len (charset) if charset_len > 256 : return charset[:256 ] r = 256 // charset_len m = 256 % charset_len s = '' for i in charset[:m]: s += i * (r + 1 ) for i in charset[m:]: s += i * r return s def image2char (image, width, height, charset ): image = image.convert('L' ).resize((width, height)) pix = image.load() char_set = [] for i in range (height): for j in range (width): char = charset[pix[j, i]] char_set.append(char) char_set.append('\r\n' ) return '' .join(char_set) def gif2char (gif, width, height, charset ): gif = Image.open (gif) gif.seek(1 ) char_set = [] count = 0 try : while True : char_set.append(CHAR_TEMP % image2char(gif, width, height, charset)) if count % 10 == 0 : print('生成 %d S 字符画' % (count / 10 )) count += 1 gif.seek(gif.tell() + 1 ) except EOFError: return '' .join(char_set) def video2gif (video, width, height ): os.system('ffmpeg -i %s -s %d*%d -r 10 %s.gif' % (video, width, height, video)) if __name__ == '__main__' : with open ('config.json' ) as fr: data = json.loads(fr.read()) charset = charset256(data['charset' ]) width = data['width' ] height = data['height' ] file = data['file' ] video2gif(file, width, height) char = gif2char(file + '.gif' , width, height, charset) with open (file + '.html' , 'w' ) as fr: fr.write(JAVASCRIPT + STYLE + char) webbrowser.open ("goodluck.mp4.html" )
效果:
参考资料 以上内容部分来源于:
【Python AsciiArt】利用命令行打印出字符图案