What is term-img?
The term-img npm package allows you to display images in the terminal. It supports various image formats and provides a simple API to render images directly in the terminal window.
What are term-img's main functionalities?
Display Image
This feature allows you to display an image in the terminal by specifying the path to the image file.
const termImg = require('term-img');
termImg('path/to/image.jpg');
Fallback Function
This feature allows you to specify a fallback function that will be called if the image cannot be displayed in the terminal.
const termImg = require('term-img');
termImg('path/to/image.jpg', { fallback: () => console.log('Image could not be displayed') });
Handle Different Image Formats
This feature demonstrates the ability to handle different image formats such as PNG and GIF.
const termImg = require('term-img');
termImg('path/to/image.png');
termImg('path/to/image.gif');
Other packages similar to term-img
terminal-image
The terminal-image package also allows you to display images in the terminal. It supports more advanced features like resizing and supports more image formats. Compared to term-img, terminal-image offers more customization options for rendering images.
image-to-ascii
The image-to-ascii package converts images to ASCII art and displays them in the terminal. While it doesn't display the actual image, it provides a unique way to visualize images using ASCII characters. This package is more focused on artistic representation rather than accurate image rendering.
term-img
Display images in iTerm
You probably want the higher-level terminal-image
package for displaying your images.

Even animated gifs!
Currently only supported on iTerm >=3.
Install
npm install term-img
Usage
import terminalImage from 'term-img';
function fallback() {
}
console.log(terminalImage('unicorn.jpg', {fallback}));
API
terminalImage(image, options?)
Get the image as a string
that you can log manually.
image
Type: string | Uint8Array
File path to an image or an image as a buffer.
options
Type: object
width
height
Type: 'auto' | string | number
The width and height are given as a number followed by a unit, or the word 'auto'
.
N
: N character cells.Npx
: N pixels.N%
: N percent of the session's width or height.auto
: The image's inherent size will be used to determine an appropriate dimension.
preserveAspectRatio
Type: boolean
Default: true
fallback
Type: Function
Default: () => throw new UnsupportedTerminalError()
Enables you to do something else when the terminal doesn't support images.
Related