ascii-arter 1.1__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,18 @@
1
+ END-USER LICENSE AGREEMENT (EULA)
2
+
3
+ This End-User License Agreement (the "Agreement") is a legally binding contract entered into by and between the Author (the Copyright Owner) and any individual or legal entity (the "User") accessing, downloading, or using this software.
4
+
5
+ 1. GRANT OF LICENSE
6
+ The Author hereby grants the User a royalty-free, non-exclusive license to download, install, and run this software solely for personal, educational, and non-commercial purposes.
7
+
8
+ 2. RESTRICTIONS
9
+ The User is strictly prohibited from engaging in any of the following activities:
10
+ • Using the software, any parts thereof, or derivative components for commercial purposes (including, but not limited to, generating profit, integrating into business processes, or utilizing within paid services).
11
+ • Copying, modifying, altering, translating, or creating derivative works based on this code without prior written permission from the Author.
12
+ • Redistributing the software or modified versions of the code under the User’s own name or through unauthorized channels.
13
+
14
+ 3. DISCLAIMER OF WARRANTY
15
+ The software is provided "as is", without warranty of any kind, express or implied. In no event shall the Author be liable for any claim, damages, or other liability arising from the use of the software.
16
+
17
+ 4. COPYRIGHT
18
+ All rights, title, and interest in and to the source code are reserved by and belong exclusively to the Author: Danil Merkushev (den-merk), 2026. All rights reserved.
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.5
2
+ Name: ascii-arter
3
+ Version: 1.1
4
+ Summary: A library for converting images and video into ASCII art
5
+ Author: Danil Merkushev
6
+ Keywords: ascii,ascii-art,console,image,terminal
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: License :: Other/Proprietary License
10
+ Classifier: Operating System :: Microsoft :: Windows :: Windows 10
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: pillow
18
+ Requires-Dist: rich
19
+ Description-Content-Type: text/markdown
20
+
21
+ # ASCII-Arter
22
+ > ASCII Arter? — Yes 🎨
23
+
24
+ **ASCII-Arter** is a Python library that transforms regular images into **ASCII art**, converting them into text format while preserving details or colors.
25
+
26
+ > ⚠️ **Important Note:** Currently, this library only works and has been tested on **Windows 10**. Support for other operating systems (Linux/macOS) is not yet available.
27
+
28
+ ### 🌟 Features
29
+ * **Colored ASCII Art (`ColoredASCIIArt`)** — prints character-based images directly into the console while keeping the original truecolor RGB values.
30
+ * **Classic ASCII Art (`NotColoredASCIIArt`)** — converts images into plain text characters of varying density.
31
+ * **Pre-rendering mode (`is_preseted=True`)** — pre-computes the ASCII art upon initialization for instant repeated rendering.
32
+
33
+ ### 📦 Installation
34
+
35
+ ```bash
36
+ pip install ascii-arter
37
+ ```
38
+
39
+ ### 🚀 Quick Start
40
+
41
+ #### 1. Colored ASCII Art
42
+ ```python
43
+ from ascii_arter import ColoredASCIIArt
44
+
45
+ # Render automatically fitted to terminal width
46
+ art = ColoredASCIIArt("photo.jpg", is_preseted=False)
47
+ art.render()
48
+
49
+ # Or specify custom width and contrast
50
+ art.render(width=80, factor_of_contrast=1.5)
51
+ ```
52
+
53
+ #### 2. Pre-rendered Mode (Fast Output)
54
+ ```python
55
+ from ascii_arter import ColoredASCIIArt
56
+
57
+ # Pre-renders immediately at initialization (width cannot be 0)
58
+ art = ColoredASCIIArt("photo.jpg", is_preseted=True, width=100)
59
+ art.render()
60
+ ```
61
+
62
+ #### 3. Classic (Uncolored) ASCII Art
63
+ ```python
64
+ from ascii_arter import NotColoredASCIIArt
65
+
66
+ art = NotColoredASCIIArt("photo.jpg", is_preseted=False)
67
+ art.render(width=80)
68
+ ```
69
+
70
+ ### ⚖️ End-User License Agreement (EULA)
71
+
72
+ Before using this library, please make sure you read and understand the `LICENSE` file included with the package.
@@ -0,0 +1,52 @@
1
+ # ASCII-Arter
2
+ > ASCII Arter? — Yes 🎨
3
+
4
+ **ASCII-Arter** is a Python library that transforms regular images into **ASCII art**, converting them into text format while preserving details or colors.
5
+
6
+ > ⚠️ **Important Note:** Currently, this library only works and has been tested on **Windows 10**. Support for other operating systems (Linux/macOS) is not yet available.
7
+
8
+ ### 🌟 Features
9
+ * **Colored ASCII Art (`ColoredASCIIArt`)** — prints character-based images directly into the console while keeping the original truecolor RGB values.
10
+ * **Classic ASCII Art (`NotColoredASCIIArt`)** — converts images into plain text characters of varying density.
11
+ * **Pre-rendering mode (`is_preseted=True`)** — pre-computes the ASCII art upon initialization for instant repeated rendering.
12
+
13
+ ### 📦 Installation
14
+
15
+ ```bash
16
+ pip install ascii-arter
17
+ ```
18
+
19
+ ### 🚀 Quick Start
20
+
21
+ #### 1. Colored ASCII Art
22
+ ```python
23
+ from ascii_arter import ColoredASCIIArt
24
+
25
+ # Render automatically fitted to terminal width
26
+ art = ColoredASCIIArt("photo.jpg", is_preseted=False)
27
+ art.render()
28
+
29
+ # Or specify custom width and contrast
30
+ art.render(width=80, factor_of_contrast=1.5)
31
+ ```
32
+
33
+ #### 2. Pre-rendered Mode (Fast Output)
34
+ ```python
35
+ from ascii_arter import ColoredASCIIArt
36
+
37
+ # Pre-renders immediately at initialization (width cannot be 0)
38
+ art = ColoredASCIIArt("photo.jpg", is_preseted=True, width=100)
39
+ art.render()
40
+ ```
41
+
42
+ #### 3. Classic (Uncolored) ASCII Art
43
+ ```python
44
+ from ascii_arter import NotColoredASCIIArt
45
+
46
+ art = NotColoredASCIIArt("photo.jpg", is_preseted=False)
47
+ art.render(width=80)
48
+ ```
49
+
50
+ ### ⚖️ End-User License Agreement (EULA)
51
+
52
+ Before using this library, please make sure you read and understand the `LICENSE` file included with the package.
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "ascii-arter"
7
+ version = "1.1"
8
+ description = "A library for converting images and video into ASCII art"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license-files = ["LICENSE"]
12
+ authors = [{ name = "Danil Merkushev" }]
13
+ keywords = ["ascii", "ascii-art", "image", "console", "terminal"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "License :: Other/Proprietary License",
18
+ "Operating System :: Microsoft :: Windows :: Windows 10",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ ]
25
+ dependencies = [
26
+ "Pillow",
27
+ "rich"
28
+ ]
@@ -0,0 +1,4 @@
1
+ from .core import ColoredASCIIArt, NotColoredASCIIArt
2
+
3
+ __all__ = ["ColoredASCIIArt", "NotColoredASCIIArt"]
4
+ __version__ = "1.1"
@@ -0,0 +1,287 @@
1
+ import math
2
+ import os
3
+ import shutil
4
+ import sys
5
+ from PIL import Image, ImageEnhance
6
+ from rich.console import Console
7
+ from rich.text import Text
8
+
9
+
10
+ def get_average_color(pix, x, y, w, h):
11
+
12
+ rr=0
13
+ rg=0
14
+ rb=0
15
+
16
+ for i in range(max(h,1)):
17
+ for j in range(max(w,1)):
18
+ rr+=pix[x+j, y+i][0]
19
+ rg+=pix[x+j, y+i][1]
20
+ rb+=pix[x+j, y+i][2]
21
+
22
+ return (int(min(255,rr//max(w*h,1))), int(min(255,rg//max(w*h,1))), int(min(255,rb//max(w*h,1))))
23
+
24
+ class ColoredASCIIArt():
25
+ """Generates colored ASCII art from an image for terminal output.
26
+
27
+ Args:
28
+ image_path (str): Relative or absolute path to the source image file (e.g., `'photo.jpg'` or `'C:/Users/Name/.../photo.jpg'`).
29
+ is_preseted (bool, optional): If `True`, the art is pre-rendered immediately
30
+ upon initialization for much faster output later. However, when enabled,
31
+ `width` cannot be `0` (auto-fit) and the character palette (`charset`)
32
+ is locked and cannot be changed afterward. Defaults to `False`.
33
+ width (int, optional): Target width of the output art in characters.
34
+ Note: Only takes effect at initialization if `is_preseted=True`
35
+ (cannot be `0` in this mode).
36
+ factor_of_contrast (float, optional): Image contrast multiplier.
37
+ `1.0` keeps the original contrast (default). Values greater than `1.0`
38
+ increase contrast, while values between `0.0` and `1.0` decrease it.
39
+ Note: Only takes effect at initialization if `is_preseted=True`.
40
+ charset (str, optional): Character gradient ordered from darkest to
41
+ brightest. Defaults to `" .`^*-~+=:;>rilkdb#MW8&%$@"`.
42
+ Note: Only takes effect at initialization if `is_preseted=True`.
43
+ """
44
+ def __init__(self, image_path, is_preseted=False, width=0, factor_of_contrast = 1, charset = " .`^*-~+=:;>rilkdb#MW8&%$@"):
45
+ self.image_path = image_path
46
+ self.image = Image.open(image_path).convert('RGB')
47
+
48
+ self.is_preseted = is_preseted
49
+
50
+ if sys.platform == "win32":
51
+ os.system('')
52
+ self.console = Console(color_system="truecolor", force_terminal=True)
53
+
54
+ if is_preseted:
55
+ enhancer = ImageEnhance.Contrast(self.image)
56
+ image = enhancer.enhance(factor_of_contrast)
57
+ pix = image.load()
58
+
59
+ image_width = image.size[0]
60
+ image_height = image.size[1]
61
+ console_width = width
62
+ k = image_width/console_width
63
+
64
+ console_image_width = math.floor(image_width/k)
65
+ console_image_height = math.floor(image_height/k)
66
+
67
+ pol = charset
68
+
69
+ a = Text()
70
+
71
+ for y in range(math.floor(console_image_height/2)):
72
+ for x in range(console_image_width):
73
+ rgb_color = get_average_color(pix, math.floor(x*k), math.floor(y*k*2), math.floor(k), math.floor(k))
74
+
75
+ ch = pol[int((rgb_color[0]+rgb_color[1]+rgb_color[2])/3 // (256 / len(pol)))]
76
+
77
+ a.append(ch, style=f"rgb({rgb_color[0]},{rgb_color[1]},{rgb_color[2]})")
78
+ a.append("\n")
79
+
80
+ self.text = a
81
+ else:
82
+ self.text = None
83
+
84
+ def render(self, width = 0, factor_of_contrast = 1, charset = " .`^*-~+=:;>rilkdb#MW8&%$@"):
85
+ """Renders colored art.
86
+
87
+ Args:
88
+ width (int, optional): Target width of the output art in characters.
89
+ If set to `0` (default), the art automatically scales to fit the
90
+ full width of the terminal window. If a positive integer is given
91
+ (e.g., `80`), that fixed width is used.
92
+ factor_of_contrast (float, optional): Image contrast multiplier.
93
+ `1.0` keeps the original contrast (default). Values greater than `1.0`
94
+ increase contrast, while values between `0.0` and `1.0` decrease it.
95
+ charset (str, optional): Character gradient ordered from darkest to
96
+ brightest. Defaults to `" .`^*-~+=:;>rilkdb#MW8&%$@"`.
97
+ """
98
+ if self.is_preseted:
99
+ self.console.print(self.text,end="")
100
+ else:
101
+ enhancer = ImageEnhance.Contrast(self.image)
102
+ image = enhancer.enhance(factor_of_contrast)
103
+ pix = image.load()
104
+
105
+ image_width = image.size[0]
106
+ image_height = image.size[1]
107
+ if width == 0:
108
+ console_width = shutil.get_terminal_size().columns
109
+ else:
110
+ console_width = width
111
+ k = image_width/console_width
112
+
113
+ console_image_width = math.floor(image_width/k)
114
+ console_image_height = math.floor(image_height/k)
115
+
116
+ pol = charset
117
+
118
+ a = Text()
119
+
120
+ for y in range(math.floor(console_image_height/2)):
121
+ for x in range(console_image_width-1):
122
+ rgb_color = get_average_color(pix, math.floor(x*k), math.floor(y*k*2), math.floor(k), math.floor(k))
123
+
124
+ ch = pol[int((rgb_color[0]+rgb_color[1]+rgb_color[2])/3 // (256 / len(pol)))]
125
+
126
+ a.append(ch, style=f"rgb({rgb_color[0]},{rgb_color[1]},{rgb_color[2]})")
127
+ a.append("\n")
128
+
129
+ self.text = a
130
+
131
+ self.console.print(self.text,end="")
132
+
133
+ def no_color_render(self, width = 0, factor_of_contrast = 1, charset = " .`^*-~+=:;>rilkdb#MW8&%$@"):
134
+ """Renders NOT colored ASCII art.
135
+
136
+ Args:
137
+ width (int, optional): Target width of the output art in characters.
138
+ If set to `0` (default), the art automatically scales to fit the
139
+ full width of the terminal window. If a positive integer is given
140
+ (e.g., `80`), that fixed width is used.
141
+ factor_of_contrast (float, optional): Image contrast multiplier.
142
+ `1.0` keeps the original contrast (default). Values greater than `1.0`
143
+ increase contrast, while values between `0.0` and `1.0` decrease it.
144
+ charset (str, optional): Character gradient ordered from darkest to
145
+ brightest. Defaults to `" .`^*-~+=:;>rilkdb#MW8&%$@"`.
146
+ """
147
+ if self.is_preseted:
148
+ print(self.text,end="")
149
+ else:
150
+ enhancer = ImageEnhance.Contrast(self.image)
151
+ image = enhancer.enhance(factor_of_contrast)
152
+ pix = image.load()
153
+
154
+ image_width = image.size[0]
155
+ image_height = image.size[1]
156
+ if width == 0:
157
+ console_width = shutil.get_terminal_size().columns
158
+ else:
159
+ console_width = width
160
+ k = image_width/console_width
161
+
162
+ console_image_width = math.floor(image_width/k)
163
+ console_image_height = math.floor(image_height/k)
164
+
165
+ pol = charset
166
+
167
+ a = ""
168
+
169
+ for y in range(math.floor(console_image_height/2)):
170
+ for x in range(console_image_width-1):
171
+ rgb_color = get_average_color(pix, math.floor(x*k), math.floor(y*k*2), math.floor(k), math.floor(k))
172
+
173
+ ch = pol[int((rgb_color[0]+rgb_color[1]+rgb_color[2])/3 // (256 / len(pol)))]
174
+
175
+ a+=ch
176
+ a+="\n"
177
+
178
+ self.text = a
179
+
180
+ print(self.text, end="")
181
+
182
+ class NotColoredASCIIArt():
183
+ """Generates NOT colored ASCII art from an image for terminal output.
184
+
185
+ Args:
186
+ image_path (str): Relative or absolute path to the source image file (e.g., `'photo.jpg'` or `'C:/Users/Name/.../photo.jpg'`).
187
+ is_preseted (bool, optional): If `True`, the art is pre-rendered immediately
188
+ upon initialization for much faster output later. However, when enabled,
189
+ `width` cannot be `0` (auto-fit) and the character palette (`charset`)
190
+ is locked and cannot be changed afterward. Defaults to `False`.
191
+ width (int, optional): Target width of the output art in characters.
192
+ Note: Only takes effect at initialization if `is_preseted=True`
193
+ (cannot be `0` in this mode).
194
+ factor_of_contrast (float, optional): Image contrast multiplier.
195
+ `1.0` keeps the original contrast (default). Values greater than `1.0`
196
+ increase contrast, while values between `0.0` and `1.0` decrease it.
197
+ Note: Only takes effect at initialization if `is_preseted=True`.
198
+ charset (str, optional): Character gradient ordered from darkest to
199
+ brightest. Defaults to `" .`^*-~+=:;>rilkdb#MW8&%$@"`.
200
+ Note: Only takes effect at initialization if `is_preseted=True`.
201
+ """
202
+ def __init__(self, image_path, is_preseted=False, width=0, factor_of_contrast = 1, charset = " .`^*-~+=:;>rilkdb#MW8&%$@"):
203
+ self.image_path = image_path
204
+ self.image = Image.open(image_path).convert('RGB')
205
+
206
+ self.is_preseted = is_preseted
207
+
208
+ if is_preseted:
209
+ enhancer = ImageEnhance.Contrast(self.image)
210
+ image = enhancer.enhance(factor_of_contrast)
211
+ pix = image.load()
212
+
213
+ image_width = image.size[0]
214
+ image_height = image.size[1]
215
+ if width == 0:
216
+ console_width = shutil.get_terminal_size().columns
217
+ else:
218
+ console_width = width
219
+ k = image_width/console_width
220
+
221
+ console_image_width = math.floor(image_width/k)
222
+ console_image_height = math.floor(image_height/k)
223
+
224
+ pol = charset
225
+
226
+ a = ""
227
+
228
+ for y in range(math.floor(console_image_height/2)):
229
+ for x in range(console_image_width-1):
230
+ rgb_color = get_average_color(pix, math.floor(x*k), math.floor(y*k*2), math.floor(k), math.floor(k))
231
+
232
+ ch = pol[int((rgb_color[0]+rgb_color[1]+rgb_color[2])/3 // (256 / len(pol)))]
233
+
234
+ a+=ch
235
+ a+="\n"
236
+ self.text = a
237
+ else:
238
+ self.text = None
239
+
240
+ def render(self, width = 0, factor_of_contrast = 1, charset = " .`^*-~+=:;>rilkdb#MW8&%$@"):
241
+ """Renders an ASCII art.
242
+
243
+ Args:
244
+ width (int, optional): Target width of the output art in characters.
245
+ If set to `0` (default), the art automatically scales to fit the
246
+ full width of the terminal window. If a positive integer is given
247
+ (e.g., `80`), that fixed width is used.
248
+ factor_of_contrast (float, optional): Image contrast multiplier.
249
+ `1.0` keeps the original contrast (default). Values greater than `1.0`
250
+ increase contrast, while values between `0.0` and `1.0` decrease it.
251
+ charset (str, optional): Character gradient ordered from darkest to
252
+ brightest. Defaults to `" .`^*-~+=:;>rilkdb#MW8&%$@"`.
253
+ """
254
+ if self.is_preseted:
255
+ print(self.text,end="")
256
+ else:
257
+ enhancer = ImageEnhance.Contrast(self.image)
258
+ image = enhancer.enhance(factor_of_contrast)
259
+ pix = image.load()
260
+
261
+ image_width = image.size[0]
262
+ image_height = image.size[1]
263
+ if width == 0:
264
+ console_width = shutil.get_terminal_size().columns
265
+ else:
266
+ console_width = width
267
+ k = image_width/console_width
268
+
269
+ console_image_width = math.floor(image_width/k)
270
+ console_image_height = math.floor(image_height/k)
271
+
272
+ pol = charset
273
+
274
+ a = ""
275
+
276
+ for y in range(math.floor(console_image_height/2)):
277
+ for x in range(console_image_width-1):
278
+ rgb_color = get_average_color(pix, math.floor(x*k), math.floor(y*k*2), math.floor(k), math.floor(k))
279
+
280
+ ch = pol[int((rgb_color[0]+rgb_color[1]+rgb_color[2])/3 // (256 / len(pol)))]
281
+
282
+ a+=ch
283
+ a+="\n"
284
+
285
+ self.text = a
286
+
287
+ print(self.text, end="")