https://github.com/nathancordeiro/terminal-image-to-ascii
This program converts a 16bit image into ascii and display it onto the terminal.
https://github.com/nathancordeiro/terminal-image-to-ascii
ascii-art cpp terminal-graphics
Last synced: 4 months ago
JSON representation
This program converts a 16bit image into ascii and display it onto the terminal.
- Host: GitHub
- URL: https://github.com/nathancordeiro/terminal-image-to-ascii
- Owner: NathanCordeiro
- License: mit
- Created: 2024-09-15T17:08:31.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-16T12:48:20.000Z (about 1 year ago)
- Last Synced: 2025-02-07T00:20:18.309Z (8 months ago)
- Topics: ascii-art, cpp, terminal-graphics
- Language: C++
- Homepage:
- Size: 1.5 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
---
# Terminal-Image-To-Ascii
---
This project converts an image into ASCII art, displayed in the terminal with color. The program maps grayscale intensity levels of the image to specific extended ASCII characters and uses ANSI color
codes to represent the original RGB colors of the image.## Features
- Convert an image to ASCII characters based on pixel intensity.
- Preserve the original image colors using ANSI color codes.
- Adjust the ASCII art size to fit within a terminal window.## How It Works
1. **Image Loading**: The program uses `stb_image.h` to load an image in memory.
2. **Pixel Intensity to ASCII**: The grayscale intensity of each pixel is mapped to an extended ASCII character.
3. **Color Conversion**: The RGB color of each pixel is converted to an ANSI escape code.
4. **Display in Terminal**: The ASCII art is displayed in the terminal using the correct colors and characters.## Images
- ### Original Image
![]()
![]()
- ## Terminal Ascii Image
![]()
## Function Overview
| Function | Description |
|----------------------------------------------|-----------------------------------------------------------------------------|
| `getAsciiChar(int intensity)` | Maps a pixel's grayscale intensity (0–255) to an extended ASCII character. |
| `getAnsiColorCode(int r, int g, int b)` | Converts an RGB value to an ANSI escape sequence for terminal colors. |
| `convertImageToAsciiMatrix(const std::string& imagePath, int width, int height)` | Loads the image, scales it to fit the terminal, and generates a matrix of ASCII characters and color codes. |
| `displayAsciiMatrix(const std::vector>>& matrix)` | Displays the ASCII matrix in the terminal, including colors, using ANSI codes. |## Extended Ascii Characters Used
| ASCII Character | Hex Code | Description |
|-----------------|----------|----------------------------------------------|
| Space (` `) | `0x20` | Represents the lightest intensity (white). |
| `█` | `0xDB` | Represents the darkest intensity (black). |
| `▒` | `0xB2` | Medium intensity. |
| `░` | `0xB0` | Light shading. |
| `▀` | `0xFE` | Dark shading, upper half. |
| `▒` | `0xB1` | Medium-light shading. |
| `▓` | `0xB2` | Medium-dark shading. |## License
[](./LICENSE)