The Wayback Machine - https://web.archive.org/web/20240828110642/https://www.geeksforgeeks.org/display-images-on-terminal-using-python/
Open In App

Display Images on Terminal using Python

Last Updated : 04 Jul, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In this article, we will discuss how to display images on a terminal using Python. We will be using the climage module for the same. This module has the following features – 

  • It helps to convert images to its ANSI Escape Codes to be able to convert be printable on Command-Line Interfaces.
  • It allows 8/16/256 bit color codings for vivid images.
  • It provides ASCII/Unicode support for more detail and adjustable pallets for different terminal themes

Installation

This module does not come built-in with Python. To install this type the below command in the terminal.

pip install climage

After the installation, the next step is to import convert() and to_file() functions, where the former performs the task of conversion and the latter performs the task of conversion and saving to the output file if needed.

Syntax:

convert(filename, is_unicode=False, is_truecolor=False, is_256color=True, is_16color=False, is_8color=False, width=80, palette=”default”)

Parameters:
filename : Name of image file.
is_unicode :  If true, conversion is done in unicode format, otherwise ASCII characters will be used.
is_truecolor :  Whether to use RGB colors in generation, if supported by terminal. Defaults False.
is_256color : Whether to use 256 colors encoding. Defaults True.
is_16color : Whether to use 16 colors encoding. Defaults False.
is_8color : Whether to use first 8 System colors. Defaults False.
width : Number of blocks of console to be used. Defaults to 80.
palette : Sets mapping of RGB colors scheme to system colors. Options are : [“default”, “xterm”, “linuxconsole”, “solarized”, “rxvt”, “tango”, “gruvbox”, “gruvboxdark”]. Default is “default”.
 

to_file(infile, outfile, is_unicode=False, is_truecolor=False, is_256color=True, is_16color=False, is_8color=False, width=80, palette=”default”)

Parameters:
infile : The name/path of image file.
outfile :   File in which to store ANSI encoded string.

Example 1: Printing on Terminal

Image Used:

Python3




import climage
  
# converts the image to print in terminal
# inform of ANSI Escape codes
output = climage.convert('banana.png')
  
# prints output on console.
print(output)


Output : 

Example 2: Saving Encoding to file.
 

Python3




import climage
  
# saves the converted encoded string
# to banana_ansi file.
output = climage.to_file('banana.png', 'banana_ansi')


Output :  

                                                                                 …

Example 3: Working using command line 

A similar function can also be used to work with the command line using similar constructs, parameters explained in previous part.

Syntax : 

climage [-h] [-v] [–unicode | –ascii] [–truecolor | –256color | –16color | –8color] [–palette {default,xterm,linuxconsole,solarized,rxvt,tango,gruvbox,gruvboxdark}] [-w width] [-o outfile] inputfile

Working:

Example 4: Custom examples using command line 

Below example show working with customized examples setting different possible parameters. 

Example 5: Custom examples using Python code. 

Extending to previous part, this section shows how custom parameters can be used from the code to construct different images.

Python3




import climage
  
# converts the image to print in terminal
# with 8 color encoding and palette tango
output = climage.convert('banana.png', is_8color=True, 
                         palette='tango', is_256color=False)
  
# prints output on console.
print(output)


Output: 



Similar Reads

How to Display Multiple Images in One Window using OpenCV Python?
Prerequisites: Opencv In this article, we will show how to display Multiple Images In One window using OpenCV in Python. Approach Import moduleLoad the Multiple images using cv2.imread()Concatenate the images using concatenate(), with axis value provided as per orientation requirementDisplay all the images using cv2.imshow()Wait for keyboard button
1 min read
Arithmetic Operations on Images using OpenCV | Set-2 (Bitwise Operations on Binary Images)
Prerequisite: Arithmetic Operations on Images | Set-1Bitwise operations are used in image manipulation and used for extracting essential parts in the image. In this article, Bitwise operations used are : ANDORXORNOT Also, Bitwise operations helps in image masking. Image creation can be enabled with the help of these operations. These operations can
4 min read
Python | Display images with PyGame
Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, it’s up to the imagination or necessity of the developer, what type of game he/she wants to develop using this toolkit. Command to install pygame : pip in
2 min read
How to Display Multiple Images in One Figure Correctly in Matplotlib?
The easiest way to display multiple images in one figure is use figure(), add_subplot(), and imshow() methods of Matplotlib. The approach which is used to follow is first initiating fig object by calling fig=plt.figure() and then add an axes object to the fig by calling add_subplot() method. Then will display the image using imshow() method. Syntax
2 min read
How to Display Images within Tkinter Frames
Tkinter is a Python module used to create Graphical User Interface (GUI) applications. Tkinter has many widgets such as Button, Label, Text, Entry, Frame, Checkbox and more that make it easy and quick to develop desktop applications. How to Insert Image inside Frame in Tkinter?To insert an image inside a frame is the same as inserting an image in T
1 min read
Formatted text in Linux Terminal using Python
This article demonstrates how to print formatted text in Linux terminal using Python programming language. Formatted text(also called styled text or rich text) as opposed to plain text, has styling information like: color (text color, background color), style (bold or italic), and some other special features like Strike-through text, underlined tex
4 min read
Python | How to make a terminal progress bar using tqdm
Whether you’re installing software, loading a page, or doing a transaction, it always eases your mind whenever you see that small progress bar giving you an estimation of how long the process would take to complete or render. If you have a simple progress bar in your script or code, it looks very pleasing to the eye and gives proper feedback to the
6 min read
Create a new Django project in Pycharm using Pycharm Terminal
PyCharm is one of the most popular Python-IDE developed by JetBrains used for performing scripting in Python language. PyCharm provides many useful features like Code completion and inspection, Debugging process, support for various programming frameworks such as Flask and Django, Package Management, etc. PyCharm provides various tools for producti
2 min read
Print Colors in Python terminal
In this article, we will cover how to print colored text in Python using several methods to output colored text to the terminal in Python. The most common ways to do this are using: Using colorama ModuleUsing termcolor ModuleUsing ANSI Code in PythonMethod 1: Print Color Text using colorama Module Colorama module is a Cross-platform printing of col
3 min read
Executing functions with multiple arguments at a terminal in Python
Commandline arguments are arguments provided by the user at runtime and gets executed by the functions or methods in the program. Python provides multiple ways to deal with these types of arguments. The three most common are: Using sys.argv Using getopt module/li> Using argparse module The Python sys module allows access to command-line argument
4 min read
Open and Run Python Files in the Terminal
The Linux terminal offers a powerful environment for working with Python files, providing developers with efficient ways to open, edit, and run Python scripts directly from the command line. Open and Run Python Files in the Linux TerminalIn this article, we'll explore various techniques and commands for handling Python files in the Linux terminal,
1 min read
Building a terminal based online dictionary with Python and bash
I was watching a movie yesterday and I didn’t understand some of the words used. So what I did was, each time I didn’t understand any word, I’d fire up my browser and type in ‘define [word]’ and google would turn me up with the meaning of the word. But it’s annoying to open the browser every time (Blame me for that ;P). What do we geeks users love
4 min read
How to Exit a Python Program in the Terminal
Exiting a Python program might seem like a straightforward task, but there are several ways to do it depending on the context and requirements of your script. Whether you want to gracefully shut down your application or terminate it immediately, knowing the right approach can help you manage your code more effectively. In this article, we will expl
3 min read
How to run an .ipynb Jupyter Notebook from terminal?
Let's see how to run Notebook in Jupyter from a terminal in this article, but first, let's get a sense of what these terms mean. Python: Python is a versatile and high-level programming language known for its readability and extensive libraries, making it a popular choice for web development, data analysis, artificial intelligence, and more.Jupyter
2 min read
Python | Create video using multiple images using OpenCV
As we know OpenCV is a widely used library for image processing. It provides a wide sense of image processing. Let's see how to create video using multiple images using OpenCV. Install the following libraries: PIL cv2 Also, check the path before running the code otherwise you will be full with errors. How it works ? Using PIL library we are opening
3 min read
How to create walking character using multiple images from sprite sheet using Pygame?
In this article, we will cover how to create a walking character using multiple images from a sprite sheet using Pygame. Any video or films that are made are actually the frames of pictures or images. The more the frame of images one has more will be the smoothness of that film or video. In sprite, we can develop any video or game with the use of i
5 min read
Get emotions of images using Microsoft emotion API in Python
The emotions of images like happy, sad, neutral, surprise, etc. can be extracted using Microsoft emotion API for any development purpose. It is very simple to use and can be called via API through terminal or any of languages like Python or PHP. Microsoft provides free subscription of 30 days for making total of 30,000 requests. The details of the
2 min read
Addition and Blending of images using OpenCV in Python
When we talk about images, we know its all about the matrix either binary image(0, 1), gray scale image(0-255) or RGB image(255 255 255). So additions of the image is adding the numbers of two matrices. In OpenCV, we have a command cv2.add() to add the images. Below is code for Addition of two images using OpenCV : # Python program for adding # ima
2 min read
Python | Denoising of colored images using opencv
Denoising of an image refers to the process of reconstruction of a signal from noisy images. Denoising is done to remove unwanted noise from image to analyze it in better form. It refers to one of the major pre-processing steps. There are four functions in opencv which is used for denoising of different images. Syntax: cv2.fastNlMeansDenoisingColor
1 min read
How to download Google Images using Python
Python is a multi-purpose language and widely used for scripting. We can write Python scripts to automate day-to-day things. Let’s say we want to download google images with multiple search queries. Instead of doing it manually we can automate the process. How to install needed Module : pip install google_images_download Let’s see how to write a Py
2 min read
Python | Working with PNG Images using Matplotlib
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. It was introduced by John Hunter in the year 2002. One of the greatest benefits of visualization is that it allows us visual access to hug
3 min read
How to Detect Shapes in Images in Python using OpenCV?
Prerequisites: OpenCV OpenCV is an open source library used mainly for processing images and videos to identify shapes, objects, text etc. It is mostly used with python. In this article we are going to see how to detect shapes in image. For this we need cv2.findContours() function of OpenCV, and also we are going to use cv2.drawContours() function
3 min read
How to subtract two images using Python-OpenCV ?
In this article, we are going to see how to subtract two images using OpenCV in Python. Now, before getting into the topic we shall discuss some of the use cases of Arithmetic operations. Arithmetic operations like addition and subtraction can help us to make images brighter or darker. Specifically, subtraction of two images has a lot of purposes i
3 min read
Working with Images in Python using Matplotlib
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. Working with Images in Python using Matplotlib The image module in matplotlib library is used for working with images in Python. The image
3 min read
Measure similarity between images using Python-OpenCV
Prerequisites: Python OpenCVSuppose we have two data images and a test image. Let's find out which data image is more similar to the test image using python and OpenCV library in Python.Let's first load the image and find out the histogram of images.Importing library import cv2 Importing image data image = cv2.imread('test.jpg') Converting to gray
2 min read
Concatenate images using OpenCV in Python
To concatenate images vertically and horizontally with Python, cv2 library comes with two functions as: hconcat(): It is used as cv2.hconcat() to concatenate images horizontally. Here h means horizontal.vconcat(): It is used as cv2.vconcat() to concatenate images vertically. Here v means vertical.Implementation using hconcat() and vconcat() on Arra
3 min read
Adding borders to the images using Python - OpenCV
Image processing is an interesting field in today's era of Artificial Intelligence and Machine Learning. We can see the applications of image processing in our day-to-day life, like whenever we apply filter over any image (selfie) or when we want to apply some effect like blurring the image, etc. In this article, we will discuss how to add borders
1 min read
How to merge images with same size using the Python 3 module pillow?
In this article, the task is to merge image with size using the module pillow in python 3. Python 3 module pillow : This is the update of Python Imaging Library. It is a free and open-source additional library for the Python programming language that adds support for opening, manipulating, and saving many various image file formats. To merge images
2 min read
Cropping Faces from Images using OpenCV - Python
Opencv is a python library mainly used for image processing and computer vision. In this article first, we detect faces after that we crop the face from the image. Face detection is the branch of image processing that uses to detect faces. We will use a pre-trained Haar Cascade model to detect faces from the image. A haar cascade is the object dete
3 min read
How to Blur Faces in Images using OpenCV in Python?
Prerequisite: OpenCV OpenCV is a huge open-source library for computer vision, machine learning, and image processing. It can process images and videos to identify objects, faces, or even the handwriting of a human. When it is integrated with various libraries, such as Numpy which is a highly optimized library for numerical operations, then the num
2 min read
Article Tags :
Practice Tags :