Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/term-img
Display images in iTerm
https://github.com/sindresorhus/term-img
cli-utility image iterm2 nodejs npm-package terminal-image
Last synced: about 13 hours ago
JSON representation
Display images in iTerm
- Host: GitHub
- URL: https://github.com/sindresorhus/term-img
- Owner: sindresorhus
- License: mit
- Created: 2016-03-09T10:57:34.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2024-07-26T12:44:53.000Z (5 months ago)
- Last Synced: 2024-11-21T01:07:47.898Z (22 days ago)
- Topics: cli-utility, image, iterm2, nodejs, npm-package, terminal-image
- Language: JavaScript
- Homepage:
- Size: 924 KB
- Stars: 309
- Watchers: 7
- Forks: 12
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
- Security: .github/security.md
Awesome Lists containing this project
- awesome-github-star - term-img
- awesome-cli - term-img - Display images in iTerm. (Output)
README
# term-img
> Display images in iTerm
You probably want the higher-level [`terminal-image`](https://github.com/sindresorhus/terminal-image) package for displaying your images.
![](screenshot.jpg)
Even [animated gifs](https://github.com/vdemedes/gifi)!
*Currently only supported on [iTerm >=3](https://www.iterm2.com/downloads.html).*
## Install
```sh
npm install term-img
```## Usage
```js
import terminalImage from 'term-img';function fallback() {
// Return something else when not supported
}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
##### heightType: `'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
- [term-img-cli](https://github.com/sindresorhus/term-img-cli) - CLI for this module
- [term-kitty-img](https://github.com/tbjgolden/term-kitty-img) - Similar package but for Kitty, Konsole, WezTerm