ascii-art-python 0.1.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) 2026 Guillem Prieur
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 @@
1
+ recursive-include ascii_art_python/assets/fonts *
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: ascii_art_python
3
+ Version: 0.1.0
4
+ Summary: A Python library for converting images and videos into ASCII art.
5
+ Author-email: Guillem Prieur <prieurguillem38@gmail.com>
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: requests
13
+ Requires-Dist: pillow
14
+ Requires-Dist: tqdm
15
+ Requires-Dist: opencv-python
16
+ Dynamic: license-file
17
+
18
+ # Ascii Art Python
19
+
20
+ Une bibliothèque Python permettant de convertir facilement des images et des vidéos en ASCII Art.
21
+
22
+ ## Installation
23
+
24
+ Vous pouvez installer la bibliothèque localement ou (si vous la publiez plus tard) via pip :
25
+
26
+ ```bash
27
+ pip install .
28
+ ```
29
+
30
+ ## Dependencies
31
+
32
+ This project uses the following libraries:
33
+
34
+ - Pillow (image manipulation)
35
+ - opencv-python (video reading and writing)
36
+ - tqdm (progress bar)
37
+ - requests
38
+
39
+ ## Usage
40
+
41
+ Here is a basic example of how to use the library:
42
+
43
+ ```python
44
+ from ascii_art_python.new_school import ImageAscii
45
+ from PIL import Image
46
+
47
+ # Load an image with Pillow
48
+ img = Image.open("mon_image.jpg")
49
+
50
+ # Convert to ASCII
51
+ ascii_converter = ImageAscii(img)
52
+ ascii_converter.export("mon_export", export_type="txt")
53
+ ```
@@ -0,0 +1,36 @@
1
+ # Ascii Art Python
2
+
3
+ Une bibliothèque Python permettant de convertir facilement des images et des vidéos en ASCII Art.
4
+
5
+ ## Installation
6
+
7
+ Vous pouvez installer la bibliothèque localement ou (si vous la publiez plus tard) via pip :
8
+
9
+ ```bash
10
+ pip install .
11
+ ```
12
+
13
+ ## Dependencies
14
+
15
+ This project uses the following libraries:
16
+
17
+ - Pillow (image manipulation)
18
+ - opencv-python (video reading and writing)
19
+ - tqdm (progress bar)
20
+ - requests
21
+
22
+ ## Usage
23
+
24
+ Here is a basic example of how to use the library:
25
+
26
+ ```python
27
+ from ascii_art_python.new_school import ImageAscii
28
+ from PIL import Image
29
+
30
+ # Load an image with Pillow
31
+ img = Image.open("mon_image.jpg")
32
+
33
+ # Convert to ASCII
34
+ ascii_converter = ImageAscii(img)
35
+ ascii_converter.export("mon_export", export_type="txt")
36
+ ```
@@ -0,0 +1,2 @@
1
+ __version__ = "0.1.0"
2
+ from . import new_school
@@ -0,0 +1,93 @@
1
+ Copyright (c) 2017-2020 Kreative Software.
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,219 @@
1
+ """
2
+ Contains all the tools needed to manage images.
3
+ """
4
+ from importlib import resources
5
+ import math
6
+ from enum import StrEnum
7
+ from tqdm import tqdm
8
+ from PIL import Image, ImageDraw, ImageFont
9
+ # pylint: disable=no-member
10
+ import cv2
11
+ import numpy
12
+
13
+ FONT = resources.files("ascii_art_python.assets.fonts").joinpath("KreativeSquare.ttf")
14
+ ASCII_CHARS: list[str] = ["#", "@", "&", "$", "{", "(", "=", "*", ";", ":", ".", " "]
15
+
16
+ class ImageAscii:
17
+ """
18
+ Class to convert and manipulate a classic image into ASCII Art.
19
+ """
20
+
21
+ class ExportType(StrEnum):
22
+ """
23
+ Used to export the image.
24
+ """
25
+ TEXT_FILE = "txt"
26
+ IMAGE_FILE = "img"
27
+
28
+ def __init__(self, image: Image.Image, max_size: int = 100_000, grid: list[str] = None) -> None:
29
+ if grid is None:
30
+ grid = ASCII_CHARS
31
+ self.grid = grid
32
+ self._source_wb = image.convert("L")
33
+ self.max_size = max_size
34
+
35
+ @property
36
+ def _ratio(self) -> float:
37
+ return math.sqrt(self.max_size / (self._source_wb.size[0] * self._source_wb.size[1]))
38
+
39
+ @property
40
+ def _size(self) -> tuple[int, int]:
41
+ return (
42
+ int(self._source_wb.size[0] * self._ratio),
43
+ int(self._source_wb.size[1] * self._ratio)
44
+ )
45
+
46
+ def to_list(self) -> list[str]:
47
+ """
48
+ Converts the image into a list of character strings.
49
+
50
+ Returns
51
+ -------
52
+ list[str]
53
+ The image in ASCII art, line by line.
54
+ """
55
+ size = self._size
56
+ ascii_list = [""] * size[1]
57
+ image = self._source_wb.resize(size)
58
+ converion_factor = len(self.grid) / 256
59
+ for i in range(size[1]):
60
+ for j in range(size[0]):
61
+ ascii_list[i] += self.grid[int(image.getpixel((j, i)) * converion_factor)]
62
+ return ascii_list
63
+
64
+ def __str__(self) -> str:
65
+ return "\n".join(self.to_list())
66
+
67
+ def __len__(self):
68
+ return self.max_size
69
+
70
+ def export(self, filename: str = "mika_export", mode: ExportType = "img") -> None:
71
+ """
72
+ TODO
73
+ """
74
+ if mode == "txt":
75
+ with open(f"{filename}.txt", "w", encoding="utf-8") as f:
76
+ f.write(str(self))
77
+
78
+ elif mode == "img":
79
+ font_size = 20
80
+ try:
81
+ font = ImageFont.truetype(FONT, font_size)
82
+ except IOError:
83
+ print(f"Warning: {FONT} not found for export. Using default font.")
84
+ font = ImageFont.load_default()
85
+
86
+ size_export = (self._size[0] * font_size, self._size[1] * font_size)
87
+
88
+ output_image = Image.new("L", size_export, color=255)
89
+ draw = ImageDraw.Draw(output_image)
90
+
91
+ for i, line in enumerate(self.to_list()):
92
+ draw.text((0, i * font_size), line, fill=0, font=font)
93
+
94
+ output_image.save(f"{filename}.png")
95
+
96
+ def to_image(self):
97
+ """
98
+ TODO
99
+ """
100
+ font_size = 20
101
+ try:
102
+ font = ImageFont.truetype(FONT, font_size)
103
+ except IOError:
104
+ print(f"Warning: {FONT} not found for export. Using default font.")
105
+ font = ImageFont.load_default()
106
+
107
+ size_export = (self._size[0] * font_size, self._size[1] * font_size)
108
+
109
+ output_image = Image.new("L", size_export, color=255)
110
+ draw = ImageDraw.Draw(output_image)
111
+
112
+ for i, line in enumerate(self.to_list()):
113
+ draw.text((0, i * font_size), line, fill=0, font=font)
114
+ return output_image
115
+
116
+ @classmethod
117
+ def from_path(cls, path: str, max_size: int = 10_000, grid: list[str] = None):
118
+ """
119
+ TODO
120
+ """
121
+ return cls(Image.open(path), max_size, grid)
122
+
123
+ class VideoAscii:
124
+ """
125
+ Class to manage the conversion of a full video into an ASCII animation.
126
+ """
127
+ def __init__(self, path: str, fps: int = 10, frame_size: int = 2_000) -> None:
128
+ self.path = path
129
+ self.max_fps = fps
130
+ self.max_frame_size = frame_size
131
+
132
+ def __iter__(self) -> iter:
133
+ cap = cv2.VideoCapture(self.path)
134
+
135
+ if not cap.isOpened():
136
+ raise ValueError(f"Error: Unable to open the video at the location '{self.path}'")
137
+
138
+ frame_skip = max(1, int(self.fps / self.max_fps))
139
+ frame_count = 0
140
+
141
+ while True:
142
+ succes, frame = cap.read()
143
+
144
+ if not succes:
145
+ break
146
+
147
+ if frame_count % frame_skip == 0:
148
+ yield ImageAscii(
149
+ Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)),
150
+ self.max_frame_size
151
+ )
152
+ frame_count += 1
153
+ cap.release()
154
+
155
+ def __len__(self) -> int:
156
+ cap = cv2.VideoCapture(self.path)
157
+
158
+ frame_skip = max(1, int(self.fps / self.max_fps))
159
+ if not cap.isOpened():
160
+ raise ValueError(f"Error: Unable to open the video at the location '{self.path}'")
161
+
162
+ lenght = int(cap.get(cv2.CAP_PROP_FRAME_COUNT) / frame_skip)
163
+ cap.release()
164
+ return lenght
165
+
166
+ @property
167
+ def fps(self) -> float:
168
+ """
169
+ TODO
170
+ """
171
+ cap = cv2.VideoCapture(self.path)
172
+
173
+ if not cap.isOpened():
174
+ raise ValueError(f"Error: Unable to open the video at the location '{self.path}'")
175
+
176
+ fps = cap.get(cv2.CAP_PROP_FPS)
177
+ cap.release()
178
+ return fps
179
+
180
+ @property
181
+ def size(self) -> tuple[int, int]:
182
+ """
183
+ TODO
184
+ """
185
+ cap = cv2.VideoCapture(self.path)
186
+
187
+ succes, frame = cap.read()
188
+
189
+ if not succes:
190
+ raise ValueError("TODO")
191
+
192
+ size = ImageAscii(
193
+ Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)),
194
+ self.max_frame_size
195
+ )._size
196
+ return (size[0] * 20, size[1] * 20)
197
+
198
+ def export(self, filename: str = "mika_export"):
199
+ """
200
+ TODO
201
+ """
202
+ fourcc = cv2.VideoWriter_fourcc(*'XVID')
203
+ print(self.size)
204
+ out = cv2.VideoWriter(
205
+ filename + ".avi",
206
+ fourcc,
207
+ self.fps / max(1, int(self.fps / self.max_fps)),
208
+ self.size, False
209
+ )
210
+
211
+ for frame in tqdm(iter(self), "Exporting frames", len(self)):
212
+ tab = numpy.array(frame.to_image())
213
+ out.write(tab)
214
+
215
+ if __name__ == "__main__":
216
+ """
217
+ TODO
218
+ """
219
+ print("TODO")
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: ascii_art_python
3
+ Version: 0.1.0
4
+ Summary: A Python library for converting images and videos into ASCII art.
5
+ Author-email: Guillem Prieur <prieurguillem38@gmail.com>
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: requests
13
+ Requires-Dist: pillow
14
+ Requires-Dist: tqdm
15
+ Requires-Dist: opencv-python
16
+ Dynamic: license-file
17
+
18
+ # Ascii Art Python
19
+
20
+ Une bibliothèque Python permettant de convertir facilement des images et des vidéos en ASCII Art.
21
+
22
+ ## Installation
23
+
24
+ Vous pouvez installer la bibliothèque localement ou (si vous la publiez plus tard) via pip :
25
+
26
+ ```bash
27
+ pip install .
28
+ ```
29
+
30
+ ## Dependencies
31
+
32
+ This project uses the following libraries:
33
+
34
+ - Pillow (image manipulation)
35
+ - opencv-python (video reading and writing)
36
+ - tqdm (progress bar)
37
+ - requests
38
+
39
+ ## Usage
40
+
41
+ Here is a basic example of how to use the library:
42
+
43
+ ```python
44
+ from ascii_art_python.new_school import ImageAscii
45
+ from PIL import Image
46
+
47
+ # Load an image with Pillow
48
+ img = Image.open("mon_image.jpg")
49
+
50
+ # Convert to ASCII
51
+ ascii_converter = ImageAscii(img)
52
+ ascii_converter.export("mon_export", export_type="txt")
53
+ ```
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ ascii_art_python/__init__.py
6
+ ascii_art_python/new_school.py
7
+ ascii_art_python.egg-info/PKG-INFO
8
+ ascii_art_python.egg-info/SOURCES.txt
9
+ ascii_art_python.egg-info/dependency_links.txt
10
+ ascii_art_python.egg-info/requires.txt
11
+ ascii_art_python.egg-info/top_level.txt
12
+ ascii_art_python/assets/fonts/KreativeSquare.ttf
13
+ ascii_art_python/assets/fonts/OFL.txt
@@ -0,0 +1,4 @@
1
+ requests
2
+ pillow
3
+ tqdm
4
+ opencv-python
@@ -0,0 +1 @@
1
+ ascii_art_python
@@ -0,0 +1,24 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ascii_art_python"
7
+ version = "0.1.0"
8
+ authors = [
9
+ { name="Guillem Prieur", email="prieurguillem38@gmail.com" },
10
+ ]
11
+ description = "A Python library for converting images and videos into ASCII art."
12
+ readme = "README.md"
13
+ requires-python = ">=3.8"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ dependencies = [
20
+ "requests",
21
+ "pillow",
22
+ "tqdm",
23
+ "opencv-python"
24
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+