在 Linux 终端将图像转换成 ASCII 艺术
ASCII
![](/data/attachment/album/202106/06/210732m5oo91ao9ws33757.png)


想在 Linux 终端中做一些有趣的事情吗？把一张普通的图片转换成 ASCII 艺术怎么样？


你知道 [什么是 ASCII](https://www.computerhope.com/jargon/a/ascii.htm) 么？它是一个标准，在 8 位码中的 256 个空位上分配字母、数字和其他字符。ASCII 艺术是一个由可打印的 ASCII 字符组成的图形。基本上，它是由一堆字母、数字和特殊字符组成的。


你可能见过有人 [以 ASCII 格式显示他们发行版的标志](https://itsfoss.com/display-linux-logo-in-ascii/)，像这样：


![](/data/attachment/album/202106/06/210807utc21z7so2gcvvq1.png)


这很酷，对吗？把一张普通的图片转换成 ASCII 艺术怎么样？这就是在这篇文章中要探讨的问题。


### Ascii Image Converter


顾名思义，[Ascii Image Converter](https://github.com/TheZoraiz/ascii-image-converter) 是一个将图片转换为 ASCII 艺术的工具。它是一个用 Go 语言编写的基于命令行的工具，它打印出提供给它的图片的ASCII版本。


你可能认不出我，但下面的图片中的 ASCII 版就是我。那是我的 8 位头像。


![](/data/attachment/album/202106/06/210807a58im8u86mm98xtj.png)


该工具支持以下格式的输入图像：


* JPEG/JPG
* PNG
* BMP
* WEBP
* TIFF/TIF


让我们看看如何安装和使用它。


### 在 Linux 上安装 Ascii Image Converter


这个有趣的工具也可以在 Windows 上使用，但我不打算这么做。在本教程中，让我们坚持使用 Linux。


如果你的发行版中启用了 [Snap](https://itsfoss.com/enable-snap-support-linux-mint/)，你可以用下面的命令轻松地安装它的 snap 包：



```
sudo snap install ascii-image-converter

```

你也可以从它的发布页面下载 Linux 的可执行文件，并把可执行文件放在 `/usr/local/bin/` 目录下。这样，你就能像普通的 Linux 命令一样运行它。如果你想知道为什么会这样，请了解一下 [Linux 目录层次结构](https://linuxhandbook.com/linux-directory-structure/)。


### 使用 Ascii Image Converter


使用很简单。安装后，你只需要提供你想转换的图像的路径。



```
ascii-image-converter path_to_image

```

你也可以提供图片的 URL，直接从网上把图片转换成 ASCII。


这是我的个人资料照片转换成 ASCII 格式。我把我的原始照片放在这里供大家参考。


![](/data/attachment/album/202106/06/210808ywceh2ztyy30ymyn.png)


你也可以转换成彩色的 ASCII。



```
ascii-image-converter -C path_to_image

```

![](/data/attachment/album/202106/06/210809zb1gmopdoapyb1rj.png)


你可以通过提供它们的路径将多个图像转换为 ASCII。它将在终端显示器上一个接一个地打印 ASCII 版本。


也有一个选项可以保存生成的 ASCII 艺术。在旧版本中，它只会被保存为文本文件，而不是图像。开发者 Zoraiz Hassan 发布了一个新版本，现在该工具默认将生成的 ASCII 图像保存为 PNG 格式。



```
ascii-image-converter path_to_image -s .

```

还有一些可用的选项，比如给输出一个特定的尺寸，使用更多的 ASCII 字符，或者使用你自己的字符集来打印 ASCII 艺术。你可以在 [项目的仓库](https://github.com/TheZoraiz/ascii-image-converter) 上阅读相关内容。


### 喜欢它吗？


你喜欢更多的 ASCII 相关的东西吗？那么 [在 Linux 上玩 ASCII 游戏](https://itsfoss.com/best-ascii-games/) 怎么样？是的，你完全可以这么做。


如果你喜欢在终端做实验，你可能会喜欢这个工具。虽然我不知道 ASCII 转换后的图像能有什么好的实际用途。有什么想法吗？




---


via: <https://itsfoss.com/ascii-image-converter/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

Want to do some fun stuff in the Linux terminal? How about converting a regular image into an ASCII art?

You know [what’s ASCII](https://www.computerhope.com/jargon/a/ascii.htm?ref=itsfoss.com)? It’s a standard that assigns letters, numbers and other characters in the 256 slots available in the 8-bit code. The ASCII art is a graphics composed of the printable ASCII characters. Basically, it is composed of a bunch of letters, numbers and special characters.

You might have seen people [displaying their distribution’s logo in ASCII format](https://itsfoss.com/display-linux-logo-in-ascii/) like this:

![Ubuntu Mate Focal Neofetch](https://itsfoss.com/content/images/wordpress/2020/04/ubuntu-mate-focal-neofetch.png)

That’s cool, right? How about converting a normal picture into ASCII art? That’s what you are going to explore in this article.

## Ascii Image Converter

As the name suggests, [Ascii Image Converter](https://github.com/TheZoraiz/ascii-image-converter?ref=itsfoss.com) is a tool that converts an image into ASCII art. It is a command line based tool written in Go and it prints the ASCII version of the image supplied to it.

You probably won’t recognize me, but that’s me in ASCII in the image below. That’s my 8-bit avatar.

![abhishek prakash in ascii](https://itsfoss.com/content/images/wordpress/2021/05/abhishek-prakash-in-ascii-800x445.png)

The tool supports input images in the following format:

- JPEG/JPG
- PNG
- BMP
- WEBP
- TIFF/TIF

Let’s see about installing and using it.

## Installing Ascii Image Converter on Linux

This nifty tool is also available on Windows but I am not going that way. Let’s stick to Linux in this tutorial.

If you have [Snap enabled in your distribution](https://itsfoss.com/enable-snap-support-linux-mint/), you can easily install its snap package using the following command:

`sudo snap install ascii-image-converter`


You may also download the Linux executable file from its release page and put the executable in the /usr/local/bin/ directory. This way, you’ll be able to run it like a regular Linux command. If you wonder why so, please learn about [Linux directory hierarchy](https://linuxhandbook.com/linux-directory-structure/?ref=itsfoss.com).

## Using Ascii Image Converter

The usage is simple. Once installed, you just have to provide the path of the image you want to convert.

`ascii-image-converter path_to_image`


You may also provide the URL of the image to convert an image into ASCII directly from the web.

Here is my profile picture converted into ASCII. I have put my original photo for the reference.

![Abhishek Prakash ascii converted](https://itsfoss.com/content/images/wordpress/2021/05/abhishek-prakash-ascii-converted-800x437.png)

You may also have a colored ASCII conversion.

`ascii-image-converter -C path_to_image`


![Abhishek colored ascii](https://itsfoss.com/content/images/wordpress/2021/05/abhishek-colored-ascii-800x429.png)

You may convert multiple images into ASCII by providing their paths. It will print the ASCII version one after another on the terminal display.

There is also an option to save the generated ASCII art. In the older version, it would be saved only as a text file, not as an image. The developer, Zoraiz Hassan, released a new version and now the tool saves the generated ASCII image in PNG format by default.

`ascii-image-converter path_to_image -s .`


There are a few more options available such as giving the output a specific dimension, use more ASCII characters, or use your own set of characters for printing the ASCII art. You can read about it on the [project’s repository](https://github.com/TheZoraiz/ascii-image-converter?ref=itsfoss.com).

## Like it?

Would you like [more ASCII stuff in the Linux terminal](https://itsfoss.com/ascii-art-linux-terminal/)? How about [playing ASCII games on Linux](https://itsfoss.com/best-ascii-games/)? Yes, you can totally do that.

If you like experimenting in the terminal, you may like this tool. However, I wonder what could be a good practical use of an ASCII-converted image. Any ideas?