Skip to content

Instantly share code, notes, and snippets.

@LeviSnoot
Created October 19, 2023 14:48
Show Gist options
  • Save LeviSnoot/f653301f11668d3ea0cba385a169ac60 to your computer and use it in GitHub Desktop.
Save LeviSnoot/f653301f11668d3ea0cba385a169ac60 to your computer and use it in GitHub Desktop.
A guide for using jp2a and jp2a2neofetch.py to create ASCII art for neofetch.

To convert an image to ASCII art, use jp2a. I found that using the Docker image was the most portable way to do this, especially as it doesn't require you to build the binary manually.

Example command:

docker run -t --rm -v "$(pwd)":/app talinx/jp2a file.ext --color-depth=4 --width=35

Command breakdown

  • docker run tells docker to run an application.
  • -t allocates a pseudo-TTY.
  • --rm makes sure to remove the container when it exits
  • -v bind mounts a volume, and in this case we're telling docker to bind our working directory ($(pwd)) to /app within the container.
  • talinx/jp2a is the docker image. You can find it here on Docker Hub. The GitHub repo may also be a valuable resource. Note: The linked repo is a fork, and that's the one we want to use. This is because that fork has the --color-depth flag whereas the original does not.
  • file.ext is the image file you want to convert. Note: This file must be placed in the working directory, otherwise the container will not be able to find it, as described in the 4th bullet point.
  • --color-depth=4 tells jp2a to output 4 colors. You can adjust this if necessary, but it's good to limit the color depth to better suit neofetch for example.
  • --width=35 character width of the resulting ASCII art.

Using jp2a2neofetch.py to create ASCII for neofetch

This Python script can be used in conjunction with jp2a to create an ASCII text file for neofetch with colors.

  1. Create jp2a2neofetch.py file in the working directory
  2. Run a jp2a command and pipe it to the Python script, then save the output to a text file
docker run -t --rm -v "$(pwd)":/app talinx/jp2a file.ext --color-depth=4 --width=35 | python3 ./jp2a2neofetch.py > output.ascii
  1. Test the result with neofetch
neofetch --ascii output.ascii --ascii_colors 1 4 5 6 7

You can edit line 6 in jp2a2neofetch.py and the above example command to change the ASCII colors used.

When satisfied with the result, you can add the output.ascii to your neofetch config.conf file.

image_backend="ascii"
image_source="/path/to/output.ascii"
ascii_colors=(1 4 5 6 7)
  • jp2a can be configured extensively to create ASCII art just the way you want it, make sure to check the man page for more info.

Credit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment