日本語の説明は下にあります
ansiart is a Python library that converts images into text art using ANSI escape sequences and outputs them to the command line interface (CLI).
It also provides the functionality to save and load ANSI escape sequences to and from text files.
By default, it uses True color, so use the truecolor_to_256color function as needed for conversion.
pip install ansiart
- image_to_ansi
- save_ansi_art
- load_ansi_art
- truecolor_to_256color
Takes the path of an image and converts that image into True Color ANSI art.
- Path of the image (str)
- Width of the image to display (int, default=150)
- Aspect ratio of the image to display (float, default=0.5)
The line spacing and aspect ratio of characters can vary by environment.
from ansiart import image_to_ansi
ansi_art = image_to_ansi("sample.png", 150, 0.5)
print(ansi_art)
Takes ANSI art and saves it to a specified text file.
- Path to save the ANSI file (str)
- ANSI art to save (str)
from ansiart import save_ansi_art
save_ansi_art("ansi_art.txt", ansi_art)
Loads ANSI art from a text file and returns it.
- Path to the text file (str)
from ansiart import load_ansi_art
ansi_art = load_ansi_art("ansi_art.txt")
Since the image_to_ansi function is based on True Color display, this function converts True Color ANSI art to 256 colors ANSI art for terminals that do not support True Color.
- ANSI art
from ansiart import truecolor_to_256color
ansi_art_256 = truecolor_to_256color(ansi_art)
If you would like to contribute, please open a pull request or issue on GitHub. All contributions are welcome.
This project is released under the MIT License. See the LICENSE file for details.
ansiartは、画像をANSIエスケープシーケンスを用いた文字アートに変換し、コマンドラインインターフェース(CLI)に出力するPythonライブラリです。
また、ANSIエスケープシーケンスをテキストファイルに保存・読み込みする機能も提供します。
デフォルトではTrue colorになっているため、適宜truecolor_to_256color関数を用いて変換してください。
pip install ansiart
- image_to_ansi
- save_ansi_art
- load_ansi_art
- truecolor_to_256color
画像のパスを受け取って、その画像をトゥルーカラーのANSIアートに変換します。
- 画像のパス(str)
- 表示する画像の横幅(int,デフォルト=150)
- 表示する画像の縦横比(float,デフォルト=0.5)
環境によって行間や文字の縦横比が異なるため。
from ansiart import image_to_ansi
ansi_art = image_to_ansi("sample.png",150,0.5)
print(ansi_art)
ANSIアートを受け取り、指定したテキストファイルに保存する。
- ANSIファイルの保存先(str)
- 保存するANSIアート(str)
from ansiart import save_ansi_art
save_ansi_art("ansi_art.txt", ansi_art)
テキストファイルからANSIアートを読み込み、それを返す
- ANSIファイルの場所(str)
from ansiart import load_ansi_art
ansi_art = load_ansi_art("ansi_art.txt")
image_to_ansi関数はTrue colorでの表示を基本とするため、サポートしていないターミナル向けにTrue colorのANSIアートを256色のANSIアートに変換します。
- ANSIアート
from ansiart import truecolor_to_256color
ansi_art_256 = truecolor_to_256color(ansi_art)
貢献したい方は、GitHubでプルリクエストやイシューを開いてください。あらゆる貢献を歓迎します。
このプロジェクトはMITライセンスの下で公開されています。詳細はLICENSEファイルを参照してください。