Terminal image with Python

natamacm

natamacm

Posted on May 13, 2020

Terminal image with Python

You can display an image in terminal. Using Python you can use the module timg.

Setup

timg is available as a package on PyPI. You can install it with pip:

$ pip install timg

Now you can use the timg command in your terminal.

usage

To display an image from code:

import timg

obj = timg.Renderer()                                                                                               
obj.load_image_from_file("test.png")                                                                                
obj.resize(100,40)
obj.render(timg.ASCIIMethod)

That turns the image into ascii art.

To run it as command line program:

    usage: timg [-h] [-V] [-i] [-m METHOD] [-r N] [-s W] [filename]

    print an image in terminal


    positional arguments:
      filename              filename of an image

    optional arguments:
      -h, --help            show this help message and exit
      -V, --version         print version and exit
      -i, --invert-background
                            invert grayscale in ASCII mode
      -m METHOD, --method METHOD
                            name of a rendering method (use `-m list` to list
                            available methods, the default is a24h)
      -r N, --reduce-colors N

                            reduce color palette of an input image (1-256)
      -s W, --size W        width of an image
💖 💪 🙅 🚩
natamacm
natamacm

Posted on May 13, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related