asciify-term 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 V33010
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,156 @@
1
+ Metadata-Version: 2.4
2
+ Name: asciify-term
3
+ Version: 0.3.0
4
+ Summary: A hybrid CLI tool for ASCII art generation with terminal and web preview modes.
5
+ Author: V33010
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/V33010/asciify
8
+ Project-URL: Bug Tracker, https://github.com/V33010/asciify/issues
9
+ Requires-Python: >=3.12
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: numpy>=2.0.0
13
+ Requires-Dist: pillow>=10.0.0
14
+ Dynamic: license-file
15
+
16
+ # Asciify Term
17
+
18
+ ![PyPI - Version](https://img.shields.io/pypi/v/asciify-term?style=flat-square&color=blue)
19
+ ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/asciify-term?style=flat-square)
20
+ ![PyPI - License](https://img.shields.io/pypi/l/asciify-term?style=flat-square)
21
+ ![PyPI - Downloads](https://img.shields.io/pypi/dm/asciify-term?style=flat-square)
22
+
23
+ **Asciify Term** is a modern, cross-platform CLI utility that renders high-resolution images as ASCII art directly in your terminal.
24
+
25
+ Originally built as a creative toy, it has evolved into a powerful **DevOps utility** for verifying image assets in headless environments (SSH, Docker, WSL) where GUI viewers are unavailable. It supports local files, remote URLs, and TrueColor rendering.
26
+
27
+ ## 🚀 Features
28
+
29
+ - **Terminal-First Workflow:** Instantly render images to stdout with zero configuration.
30
+ - **Headless Support:** Perfect for verifying plot.png or asset files on remote servers via SSH.
31
+ - **URL Support:** Fetch and render images directly from the web (http://...) without manual downloading.
32
+ - **TrueColor Support:** Renders images in full 24-bit ANSI color.
33
+ - **Smart Resizing:** Automatically fits the output to your current terminal window dimensions.
34
+ - **Export Options:** Save outputs as plain text .txt or color-preserving .html.
35
+ - **Legacy Interactive Mode:** A guided menu system for creative exploration.
36
+
37
+ ## Installation
38
+
39
+ Install directly from PyPI:
40
+
41
+ ```sh
42
+ pip install asciify-term
43
+ ```
44
+
45
+
46
+ ## Usage
47
+
48
+ ### 1. The Quick Scan (Default)
49
+
50
+ The primary use case is to quickly view an image in your terminal. The output automatically scales to fit your window.
51
+
52
+ ```sh
53
+ # Local File
54
+ asciify -i image.jpg
55
+
56
+ # Remote URL
57
+ asciify -i https://example.com/logo.png
58
+ ```
59
+
60
+ ### 2. Color Mode
61
+
62
+ To view the image with its original colors (using ANSI escape codes):
63
+ ```sh
64
+ asciify -i image.jpg --color
65
+ ```
66
+
67
+ ### 3. Saving Output
68
+
69
+ You can save the generated art to a file instead of (or in addition to) printing it.
70
+
71
+ **Save to current directory (Auto-named):**
72
+ ```sh
73
+ asciify -i image.jpg -s
74
+ # Creates: ascii_image_TIMESTAMP.txt
75
+ ```
76
+
77
+ **Save with custom name/location:**
78
+ ```sh
79
+ # Save as specific filename (no extension needed)
80
+ asciify -i image.jpg --output-file-name my_art
81
+
82
+ # Save to a specific folder
83
+ asciify -i image.jpg --output-folder ./art_gallery
84
+ ```
85
+
86
+ **Save as HTML (Preserves Color):**
87
+ ```sh
88
+ asciify -i image.jpg --color --html
89
+ ```
90
+
91
+ ### 4. Customizing Dimensions
92
+
93
+ By default, asciify fits the image to your terminal. You can override this:
94
+
95
+ ```sh
96
+ # Force specific width (Height auto-calculated)
97
+ asciify -i image.jpg --width 100
98
+
99
+ # Force specific width AND aspect ratio
100
+ asciify -i image.jpg --width 100 --aspect-ratio 2.0
101
+
102
+ # Downsize by a factor of 4
103
+ asciify -i image.jpg --downsize 4
104
+ ```
105
+
106
+ ### 5. Managing Charsets
107
+
108
+ You can change the characters used for rendering (e.g., standard ASCII, blocks, braille).
109
+
110
+ **List available charsets:**
111
+ ```sh
112
+ asciify --show-charsets
113
+ ```
114
+
115
+ **Use a specific charset for one run:**
116
+ ```sh
117
+ asciify -i image.jpg -c blocks
118
+ ```
119
+
120
+ **Set a new default charset (Persistent):**
121
+ ```sh
122
+ asciify --set-charset blocks
123
+ # All future runs will now use 'blocks' by default
124
+ ```
125
+
126
+
127
+ ## Advanced: Interactive Mode
128
+
129
+ For a more guided, "creative" experience with animations and previews, use the --full flag. This launches the legacy interactive menu.
130
+
131
+ ```sh
132
+ asciify --full
133
+ ```
134
+
135
+ ## Configuration Reference
136
+
137
+ | Flag | Description |
138
+ | :--- | :--- |
139
+ | -i, --input-file | Path to local image OR URL (http://...). |
140
+ | --color | Enable TrueColor ANSI output. |
141
+ | -s, --save | Save output to current directory. |
142
+ | --output-folder | Specify folder for saved output. |
143
+ | --output-file-name | Specify filename (without extension). |
144
+ | --html | Save as .html file. |
145
+ | --width | Set target width. |
146
+ | --height | Set target height. |
147
+ | --aspect-ratio | Force specific aspect ratio. |
148
+ | --downsize | Downsize image by factor n. |
149
+ | -c, --charset | Use specific charset string. |
150
+ | --show-charsets | List all built-in charsets. |
151
+ | --set-charset | Set default charset preference. |
152
+ | --full | Launch legacy interactive mode. |
153
+
154
+ ## License
155
+
156
+ Distributed under the MIT License. See LICENSE for more information.
@@ -0,0 +1,141 @@
1
+ # Asciify Term
2
+
3
+ ![PyPI - Version](https://img.shields.io/pypi/v/asciify-term?style=flat-square&color=blue)
4
+ ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/asciify-term?style=flat-square)
5
+ ![PyPI - License](https://img.shields.io/pypi/l/asciify-term?style=flat-square)
6
+ ![PyPI - Downloads](https://img.shields.io/pypi/dm/asciify-term?style=flat-square)
7
+
8
+ **Asciify Term** is a modern, cross-platform CLI utility that renders high-resolution images as ASCII art directly in your terminal.
9
+
10
+ Originally built as a creative toy, it has evolved into a powerful **DevOps utility** for verifying image assets in headless environments (SSH, Docker, WSL) where GUI viewers are unavailable. It supports local files, remote URLs, and TrueColor rendering.
11
+
12
+ ## 🚀 Features
13
+
14
+ - **Terminal-First Workflow:** Instantly render images to stdout with zero configuration.
15
+ - **Headless Support:** Perfect for verifying plot.png or asset files on remote servers via SSH.
16
+ - **URL Support:** Fetch and render images directly from the web (http://...) without manual downloading.
17
+ - **TrueColor Support:** Renders images in full 24-bit ANSI color.
18
+ - **Smart Resizing:** Automatically fits the output to your current terminal window dimensions.
19
+ - **Export Options:** Save outputs as plain text .txt or color-preserving .html.
20
+ - **Legacy Interactive Mode:** A guided menu system for creative exploration.
21
+
22
+ ## Installation
23
+
24
+ Install directly from PyPI:
25
+
26
+ ```sh
27
+ pip install asciify-term
28
+ ```
29
+
30
+
31
+ ## Usage
32
+
33
+ ### 1. The Quick Scan (Default)
34
+
35
+ The primary use case is to quickly view an image in your terminal. The output automatically scales to fit your window.
36
+
37
+ ```sh
38
+ # Local File
39
+ asciify -i image.jpg
40
+
41
+ # Remote URL
42
+ asciify -i https://example.com/logo.png
43
+ ```
44
+
45
+ ### 2. Color Mode
46
+
47
+ To view the image with its original colors (using ANSI escape codes):
48
+ ```sh
49
+ asciify -i image.jpg --color
50
+ ```
51
+
52
+ ### 3. Saving Output
53
+
54
+ You can save the generated art to a file instead of (or in addition to) printing it.
55
+
56
+ **Save to current directory (Auto-named):**
57
+ ```sh
58
+ asciify -i image.jpg -s
59
+ # Creates: ascii_image_TIMESTAMP.txt
60
+ ```
61
+
62
+ **Save with custom name/location:**
63
+ ```sh
64
+ # Save as specific filename (no extension needed)
65
+ asciify -i image.jpg --output-file-name my_art
66
+
67
+ # Save to a specific folder
68
+ asciify -i image.jpg --output-folder ./art_gallery
69
+ ```
70
+
71
+ **Save as HTML (Preserves Color):**
72
+ ```sh
73
+ asciify -i image.jpg --color --html
74
+ ```
75
+
76
+ ### 4. Customizing Dimensions
77
+
78
+ By default, asciify fits the image to your terminal. You can override this:
79
+
80
+ ```sh
81
+ # Force specific width (Height auto-calculated)
82
+ asciify -i image.jpg --width 100
83
+
84
+ # Force specific width AND aspect ratio
85
+ asciify -i image.jpg --width 100 --aspect-ratio 2.0
86
+
87
+ # Downsize by a factor of 4
88
+ asciify -i image.jpg --downsize 4
89
+ ```
90
+
91
+ ### 5. Managing Charsets
92
+
93
+ You can change the characters used for rendering (e.g., standard ASCII, blocks, braille).
94
+
95
+ **List available charsets:**
96
+ ```sh
97
+ asciify --show-charsets
98
+ ```
99
+
100
+ **Use a specific charset for one run:**
101
+ ```sh
102
+ asciify -i image.jpg -c blocks
103
+ ```
104
+
105
+ **Set a new default charset (Persistent):**
106
+ ```sh
107
+ asciify --set-charset blocks
108
+ # All future runs will now use 'blocks' by default
109
+ ```
110
+
111
+
112
+ ## Advanced: Interactive Mode
113
+
114
+ For a more guided, "creative" experience with animations and previews, use the --full flag. This launches the legacy interactive menu.
115
+
116
+ ```sh
117
+ asciify --full
118
+ ```
119
+
120
+ ## Configuration Reference
121
+
122
+ | Flag | Description |
123
+ | :--- | :--- |
124
+ | -i, --input-file | Path to local image OR URL (http://...). |
125
+ | --color | Enable TrueColor ANSI output. |
126
+ | -s, --save | Save output to current directory. |
127
+ | --output-folder | Specify folder for saved output. |
128
+ | --output-file-name | Specify filename (without extension). |
129
+ | --html | Save as .html file. |
130
+ | --width | Set target width. |
131
+ | --height | Set target height. |
132
+ | --aspect-ratio | Force specific aspect ratio. |
133
+ | --downsize | Downsize image by factor n. |
134
+ | -c, --charset | Use specific charset string. |
135
+ | --show-charsets | List all built-in charsets. |
136
+ | --set-charset | Set default charset preference. |
137
+ | --full | Launch legacy interactive mode. |
138
+
139
+ ## License
140
+
141
+ Distributed under the MIT License. See LICENSE for more information.
@@ -0,0 +1,23 @@
1
+ [build-system]
2
+ requires = [ "setuptools", "wheel",]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "asciify-term"
7
+ version = "0.3.0"
8
+ description = "A hybrid CLI tool for ASCII art generation with terminal and web preview modes."
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ dependencies = [ "numpy>=2.0.0", "pillow>=10.0.0",]
12
+ [[project.authors]]
13
+ name = "V33010"
14
+
15
+ [project.license]
16
+ text = "MIT"
17
+
18
+ [project.scripts]
19
+ asciify = "ascii_art.cli:main"
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/V33010/asciify"
23
+ "Bug Tracker" = "https://github.com/V33010/asciify/issues"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,2 @@
1
+ # src/ascii_art/__init__.py
2
+ # Exposes the package
@@ -0,0 +1,5 @@
1
+ # src/ascii_art/__main__.py
2
+ from .cli import main
3
+
4
+ if __name__ == "__main__":
5
+ main()
@@ -0,0 +1 @@
1
+ __version__ = "0.3.0"
@@ -0,0 +1,69 @@
1
+ # src/ascii_art/charset.py
2
+ import json
3
+ from pathlib import Path
4
+
5
+ # Define available charsets in a dictionary for easy lookup
6
+ CHARSETS = {
7
+ "default": " .:;!|)]>#$@%",
8
+ "simple": " .:-=+*#%@",
9
+ "blocks": " ░▒▓█",
10
+ "blocks_extended": " ░░▒▒▓▓██",
11
+ "binary": "10",
12
+ "cyberpunk": " .:?08NM",
13
+ "braille": " ⠐⠠⢀⠂⠔⢄⠒⠤⢆⠖⠦⢖⠶⠷⡷⠿⣟⣯⣷⣾⣿",
14
+ "braille_small": "⠀⠁⠃⠇⠏⠟⠿⡿⣿",
15
+ "tech": " ⠂⠔⠦⠶⠷▏░⠿▎▍▒▓▌▟▋▊▉█",
16
+ }
17
+
18
+ CONFIG_FILE = Path.home() / ".asciify_config.json"
19
+
20
+
21
+ def get_charset(custom_charset=None):
22
+ """
23
+ Returns the charset to use.
24
+ Priority:
25
+ 1. Custom string passed via CLI flag (-c)
26
+ 2. Persisted user preference (set via --set-charset)
27
+ 3. Default charset
28
+ """
29
+ # 1. Custom CLI Override
30
+ if custom_charset:
31
+ if isinstance(custom_charset, str) and len(custom_charset) > 0:
32
+ return custom_charset
33
+ else:
34
+ raise ValueError("Custom charset must be a non-empty string.")
35
+
36
+ # 2. Check Persistent Config
37
+ saved_charset_name = load_persistent_charset_name()
38
+ if saved_charset_name and saved_charset_name in CHARSETS:
39
+ return CHARSETS[saved_charset_name]
40
+
41
+ # 3. Default
42
+ return CHARSETS["default"]
43
+
44
+
45
+ def set_persistent_charset(charset_name):
46
+ """Saves the user's preferred charset name to a local config file."""
47
+ if charset_name not in CHARSETS:
48
+ available = ", ".join(CHARSETS.keys())
49
+ raise ValueError(f"Invalid charset '{charset_name}'. Available: {available}")
50
+
51
+ try:
52
+ data = {"charset": charset_name}
53
+ with open(CONFIG_FILE, "w") as f:
54
+ json.dump(data, f)
55
+ print(f"✅ Default charset set to: {charset_name}")
56
+ except Exception as e:
57
+ print(f"❌ Failed to save config: {e}")
58
+
59
+
60
+ def load_persistent_charset_name():
61
+ """Loads the preferred charset name if it exists."""
62
+ if not CONFIG_FILE.exists():
63
+ return None
64
+ try:
65
+ with open(CONFIG_FILE, "r") as f:
66
+ data = json.load(f)
67
+ return data.get("charset")
68
+ except Exception:
69
+ return None
@@ -0,0 +1,166 @@
1
+ # src/ascii_art/cli.py
2
+ import argparse
3
+ import os
4
+ import sys
5
+ from pathlib import Path
6
+
7
+ from . import charset as charset_mod
8
+ from . import (converter, image_loader, image_resize, server, terminal, ui,
9
+ writer)
10
+
11
+
12
+ def parse_args():
13
+ parser = argparse.ArgumentParser(
14
+ description="Asciify: Terminal-first ASCII Art Generator", add_help=True
15
+ )
16
+
17
+ # --- INPUT ---
18
+ parser.add_argument("-i", "--input-file", help="Path to input image file")
19
+
20
+ # --- MODE SWITCH ---
21
+ parser.add_argument(
22
+ "--full", action="store_true", help="Launch the legacy interactive mode"
23
+ )
24
+
25
+ # --- OUTPUT FLAGS ---
26
+ parser.add_argument(
27
+ "-s", "--save", action="store_true", help="Save output to current directory"
28
+ )
29
+ parser.add_argument("--output-folder", help="Specify directory for saved output")
30
+ parser.add_argument(
31
+ "--output-file-name", help="Specify filename (WITHOUT extension)"
32
+ )
33
+ parser.add_argument(
34
+ "--html", action="store_true", help="Save as HTML file (preserves color)"
35
+ )
36
+ parser.add_argument("--color", action="store_true", help="Enable colorized output")
37
+
38
+ # --- DIMENSION FLAGS ---
39
+ parser.add_argument("--width", type=int, help="Target width")
40
+ parser.add_argument("--height", type=int, help="Target height")
41
+ parser.add_argument("--aspect-ratio", type=float, help="Target aspect ratio")
42
+ parser.add_argument("--downsize", type=float, help="Downsize factor (n)")
43
+
44
+ # --- CHARSET FLAGS ---
45
+ parser.add_argument(
46
+ "--show-charsets", action="store_true", help="List available charsets"
47
+ )
48
+ parser.add_argument("--set-charset", help="Set the default charset for future runs")
49
+ parser.add_argument(
50
+ "-c", "--charset", help="Use a specific charset string for this run"
51
+ )
52
+
53
+ # --- LEGACY/FULL MODE ONLY ---
54
+ parser.add_argument(
55
+ "--no-preview", action="store_true", help="Skip preview (Full mode only)"
56
+ )
57
+ parser.add_argument(
58
+ "--no-animate", action="store_true", help="Disable animation (Full mode only)"
59
+ )
60
+
61
+ # Parse
62
+ args = parser.parse_args()
63
+ return args
64
+
65
+
66
+ def run_legacy_interactive_mode(args):
67
+ """
68
+ The old interactive workflow for --full flag
69
+ """
70
+ if args.no_animate:
71
+ ui.CONFIG["animate"] = False
72
+
73
+ ui.print_header()
74
+
75
+ # Image Selection
76
+ img_path = None
77
+ if args.input_file:
78
+ p = Path(args.input_file)
79
+ if not p.exists():
80
+ ui.cool_print(f"Error: Input path '{args.input_file}' does not exist.\n")
81
+ sys.exit(1)
82
+ img_path = p
83
+ else:
84
+ img_path = image_loader.list_and_select_image()
85
+ if not img_path:
86
+ return
87
+
88
+ # Load Image
89
+ do_preview = not args.no_preview
90
+ img = image_loader.load_image(img_path, preview=do_preview)
91
+ if not img:
92
+ return
93
+
94
+ # Dimensions
95
+ target_w, target_h = None, None
96
+
97
+ # Check flags first, else interactive
98
+ if args.width or args.height:
99
+ try:
100
+ target_w, target_h = image_resize.calculate_dimensions(
101
+ img, args.width, args.height, args.aspect_ratio
102
+ )
103
+ except ValueError as e:
104
+ ui.cool_print(f"Error: {e}\n")
105
+ sys.exit(1)
106
+
107
+ if target_w is None or target_h is None:
108
+ target_w, target_h = image_resize.interactive_downsize_factor(img)
109
+
110
+ # Resize
111
+ img_resized = image_resize.resize_image(img, target_w, target_h)
112
+
113
+ # Charset
114
+ try:
115
+ chars = charset_mod.get_charset(args.charset)
116
+ except ValueError as e:
117
+ ui.cool_print(f"Error: {e}\n")
118
+ sys.exit(1)
119
+
120
+ # Convert
121
+ ui.cool_print(f"Converting to {target_w}x{target_h}...\n")
122
+ ascii_grid = converter.image_to_ascii(img_resized, chars)
123
+
124
+ # Save
125
+ output_path = writer.save_art(
126
+ ascii_grid, img_path, output_name=args.output_file_name
127
+ )
128
+ if not output_path:
129
+ return
130
+
131
+ # Server
132
+ ui.clear_terminal()
133
+ server.start_server_and_open_browser(output_path)
134
+ ui.cool_print("\nServer is running. Check your browser.\n")
135
+
136
+
137
+ def main():
138
+ args = parse_args()
139
+
140
+ # --- 1. CHECK FOR NO ARGS ---
141
+ if len(sys.argv) == 1:
142
+ # "python -m src.ascii_art -> this will DO NOTHING, AND JUST THROW AN ERROR"
143
+ print("Error: No arguments provided.")
144
+ print("Usage: asciify -i <input_file> [options]")
145
+ print("Try 'asciify --help' for details.")
146
+ sys.exit(1)
147
+
148
+ # --- 2. BRANCH: FULL INTERACTIVE MODE ---
149
+ if args.full:
150
+ while True:
151
+ run_legacy_interactive_mode(args)
152
+ # Legacy loop logic
153
+ ui.cool_print("Enter 1 to run again, or any other key to exit: ")
154
+ choice = input().strip()
155
+ if choice != "1":
156
+ ui.clear_terminal()
157
+ sys.exit()
158
+ ui.clear_terminal()
159
+
160
+ # --- 3. BRANCH: TERMINAL MODE (DEFAULT) ---
161
+ # This handles -i, configuration, printing, and saving
162
+ terminal.run_terminal_pipeline(args)
163
+
164
+
165
+ if __name__ == "__main__":
166
+ main()
@@ -0,0 +1,62 @@
1
+ # src/ascii_art/converter.py
2
+ import numpy as np
3
+
4
+
5
+ def image_to_ascii(img, charset):
6
+ """
7
+ Converts a PIL image to a 2D list of characters (Grayscale).
8
+ """
9
+ arr = np.array(img)
10
+
11
+ # Handle dimensions (Height, Width)
12
+ # Convert to grayscale logic: max(R, G, B)
13
+ if len(arr.shape) == 3:
14
+ # Vectorized operation: max across channel axis (axis 2)
15
+ gray_arr = np.max(arr[:, :, :3], axis=2)
16
+ else:
17
+ gray_arr = arr
18
+
19
+ # Normalize to charset length
20
+ scale = (len(charset) - 1) / 255
21
+ indices = (gray_arr * scale).astype(int)
22
+
23
+ # Map indices to characters
24
+ ascii_grid = []
25
+ for row in indices:
26
+ ascii_row = [charset[i] for i in row]
27
+ ascii_grid.append(ascii_row)
28
+
29
+ return ascii_grid
30
+
31
+
32
+ def image_to_ascii_with_color(img, charset):
33
+ """
34
+ Converts a PIL image to a 2D list of tuples: (character, (r, g, b)).
35
+ """
36
+ # Ensure image is RGB to guarantee 3 channels
37
+ img_rgb = img.convert("RGB")
38
+ arr = np.array(img_rgb)
39
+
40
+ # 1. Get Grayscale values for Char selection
41
+ gray_arr = np.max(arr, axis=2)
42
+
43
+ # 2. Normalize for charset index
44
+ scale = (len(charset) - 1) / 255
45
+ indices = (gray_arr * scale).astype(int)
46
+
47
+ # 3. Build the grid
48
+ # This results in a list of rows, where each item is (char, (r,g,b))
49
+ colored_grid = []
50
+
51
+ rows, cols, _ = arr.shape
52
+
53
+ for i in range(rows):
54
+ row_data = []
55
+ for j in range(cols):
56
+ char_idx = indices[i, j]
57
+ char = charset[char_idx]
58
+ rgb = tuple(arr[i, j]) # (R, G, B)
59
+ row_data.append((char, rgb))
60
+ colored_grid.append(row_data)
61
+
62
+ return colored_grid