Skip to content

Commit 48e2983

Browse files
committed
Update 2.2.0 (RELEASE)
1 parent 4b88483 commit 48e2983

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
[tool.poetry]
22
name = "ripix"
3-
version = "2.2.0"
3+
version = "2.2.1"
44
description = "A Rich-compatible library for writing pixel images and ASCII art to the terminal."
55
authors = ["Darren Burns <darrenb900@gmail.com>", "Romanin <semina054@gmail.com>"]
6+
repository = "https://github.com/romanin-rf/ripix"
7+
keywords = ["ripix", "rich", "textual", "image", "ascii-art", "rich_pixels"]
68
readme = "README.md"
79
packages = [{ include = "ripix" }]
810
include = ["ripix/py.typed", "ripix/functions.pyi"]

ripix/functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
async def aiter(it):
55
for item in it:
66
yield item
7-
asyncio.sleep(0)
7+
await asyncio.sleep(0)
88

99
async def arange(*args, **kwargs) -> int:
1010
for i in range(*args, **kwargs):
1111
yield i
12-
asyncio.sleep(0)
12+
await asyncio.sleep(0)
1313

1414
async def run_in_executor(loop, executor, func, *args, **kwargs):
1515
if loop is None: loop = asyncio.get_running_loop()

ripix/pixel.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# > Local Imports
1515
from .functions import arange, aiter, wrapper_run_in_executor, run_in_executor
1616

17-
1817
# ! Just Pixels
1918
class Pixels:
2019
def __init__(self) -> None:
@@ -66,13 +65,12 @@ def _segments_from_image(
6665
for x in range(width):
6766
r, g, b, a = get_pixel((x, y))
6867
style = parse_style(f"on rgb({r},{g},{b})") if a > 0 else null_style
69-
row_append(Segment(" ", style))
68+
row_append(Segment(" ", style))
7069

7170
row_append(Segment("\n", null_style))
7271

7372
# TODO: Double-check if this is required - I've forgotten...
74-
if not all(t[1] == "" for t in this_row[:-1]):
75-
segments += this_row
73+
segments += this_row
7674

7775
return segments
7876

@@ -128,17 +126,20 @@ def __init__(self) -> None:
128126
async def from_image(
129127
image: Image,
130128
resize: Optional[Tuple[int, int]] = None,
129+
resample: Optional[Resampling] = None,
131130
loop: Optional[AbstractEventLoop] = None
132131
) -> AsyncPixels:
133132
if loop is None: loop = get_running_loop()
133+
resample = resample or Resampling.NEAREST
134134

135-
segments = await AsyncPixels._segments_from_image(image, resize, loop)
135+
segments = await AsyncPixels._segments_from_image(image, resize, resample, loop)
136136
return AsyncPixels.from_segments(segments)
137137

138138
@staticmethod
139139
async def from_image_path(
140140
path: Union[PurePath, str],
141141
resize: Optional[Tuple[int, int]] = None,
142+
resample: Optional[Resampling] = None,
142143
loop: Optional[AbstractEventLoop] = None
143144
) -> AsyncPixels:
144145
"""Create a Pixels object from an image. Requires 'image' extra dependencies.
@@ -147,22 +148,26 @@ async def from_image_path(
147148
path: The path to the image file.
148149
resize: A tuple of (width, height) to resize the image to.
149150
"""
151+
resample = resample or Resampling.NEAREST
152+
150153
if loop is None: loop = get_running_loop()
151154
pilopen = wrapper_run_in_executor(loop, None, PILImageModule.open)
152155

153156
with await pilopen(Path(path)) as image:
154-
segments = await AsyncPixels._segments_from_image(image, resize, loop)
157+
segments = await AsyncPixels._segments_from_image(image, resize, resample, loop)
155158

156159
return await AsyncPixels.from_segments(segments)
157160

158161
@staticmethod
159162
async def _segments_from_image(
160163
image: Image,
161164
resize: Optional[Tuple[int, int]] = None,
165+
resize_resample: Optional[Resampling] = None,
162166
loop: Optional[AbstractEventLoop] = None
163167
) -> List[Segment]:
168+
resample = resize_resample or Resampling.NEAREST
164169
if loop is None: loop = get_running_loop()
165-
if resize is not None: image = await run_in_executor(loop, None, image.resize, resize, resample=Resampling.NEAREST)
170+
if resize is not None: image = await run_in_executor(loop, None, image.resize, resize, resample=resample)
166171

167172
width, height = image.width, image.height
168173
rgba_image = await run_in_executor(loop, None, image.convert, "RGBA") if image.mode != "RGBA" else image
@@ -178,13 +183,10 @@ async def _segments_from_image(
178183
async for x in arange(width):
179184
r, g, b, a = await get_pixel((x, y))
180185
style = await parse_style(f"on rgb({r},{g},{b})") if (a > 0) else null_style
181-
row_append(Segment(" ", style))
182-
186+
row_append(Segment(" ", style))
183187
row_append(Segment("\n", null_style))
184-
185-
# TODO: Double-check if this is required - I've forgotten...
186-
if not all(t[1] == "" async for t in aiter(this_row[:-1])):
187-
segments += this_row
188+
189+
segments += this_row
188190

189191
return segments
190192

0 commit comments

Comments
 (0)