ipolypad 1.0.2__tar.gz → 1.0.5__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.
- {ipolypad-1.0.2 → ipolypad-1.0.5}/PKG-INFO +2 -1
- {ipolypad-1.0.2 → ipolypad-1.0.5}/README.md +1 -0
- {ipolypad-1.0.2 → ipolypad-1.0.5}/src/ipolypad/__version__.py +2 -2
- {ipolypad-1.0.2 → ipolypad-1.0.5}/src/ipolypad/pipeline.py +12 -5
- {ipolypad-1.0.2 → ipolypad-1.0.5}/src/ipolypad/trace.py +11 -1
- {ipolypad-1.0.2 → ipolypad-1.0.5}/.gitignore +0 -0
- {ipolypad-1.0.2 → ipolypad-1.0.5}/pyproject.toml +0 -0
- {ipolypad-1.0.2 → ipolypad-1.0.5}/src/ipolypad/__init__.py +0 -0
- {ipolypad-1.0.2 → ipolypad-1.0.5}/src/ipolypad/__main__.py +0 -0
- {ipolypad-1.0.2 → ipolypad-1.0.5}/src/ipolypad/color.py +0 -0
- {ipolypad-1.0.2 → ipolypad-1.0.5}/src/ipolypad/emit.py +0 -0
- {ipolypad-1.0.2 → ipolypad-1.0.5}/src/ipolypad/errors.py +0 -0
- {ipolypad-1.0.2 → ipolypad-1.0.5}/src/ipolypad/fetch.py +0 -0
- {ipolypad-1.0.2 → ipolypad-1.0.5}/src/ipolypad/rasterize.py +0 -0
- {ipolypad-1.0.2 → ipolypad-1.0.5}/src/ipolypad/simplify.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ipolypad
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.5
|
|
4
4
|
Summary: Convert an image or SVG into a padded polygon hull for CSS shape-outside / text-wrap.
|
|
5
5
|
Project-URL: Homepage, https://github.com/twardoch/ipolypad
|
|
6
6
|
Project-URL: Documentation, https://code.twardoch.com/ipolypad/
|
|
@@ -35,6 +35,7 @@ Description-Content-Type: text/markdown
|
|
|
35
35
|
|
|
36
36
|
Convert an image or SVG into a **padded polygon hull** suitable for CSS
|
|
37
37
|
`shape-outside` and HTML/canvas text-wrap engines. Reference implementation.
|
|
38
|
+
Positive padding dilates the silhouette; negative padding erodes it.
|
|
38
39
|
|
|
39
40
|
See the project root [`README.md`](../README.md) and [`SPEC.md`](../SPEC.md) for
|
|
40
41
|
the full design. This package is the Python side — smart, batteries-included,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Convert an image or SVG into a **padded polygon hull** suitable for CSS
|
|
4
4
|
`shape-outside` and HTML/canvas text-wrap engines. Reference implementation.
|
|
5
|
+
Positive padding dilates the silhouette; negative padding erodes it.
|
|
5
6
|
|
|
6
7
|
See the project root [`README.md`](../README.md) and [`SPEC.md`](../SPEC.md) for
|
|
7
8
|
the full design. This package is the Python side — smart, batteries-included,
|
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '1.0.
|
|
22
|
-
__version_tuple__ = version_tuple = (1, 0,
|
|
21
|
+
__version__ = version = '1.0.5'
|
|
22
|
+
__version_tuple__ = version_tuple = (1, 0, 5)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -13,7 +13,7 @@ from .errors import EmptyMaskError, OnlyFrameError, TraceEmptyError
|
|
|
13
13
|
from .fetch import fetch, is_svg
|
|
14
14
|
from .rasterize import alpha_array, rasterize
|
|
15
15
|
from .simplify import convex_hull, decimate, normalize, pick_outer_shell, polygon_area
|
|
16
|
-
from .trace import dilate_circular, trace_mask
|
|
16
|
+
from .trace import dilate_circular, erode_circular, trace_mask
|
|
17
17
|
|
|
18
18
|
Format = Literal["json", "css", "svg", "png", "html"]
|
|
19
19
|
|
|
@@ -22,7 +22,7 @@ def _resolve_pad(*, pad: int | None, pad_pct: float | None, size: int) -> int:
|
|
|
22
22
|
if pad is not None and pad_pct is not None:
|
|
23
23
|
raise ValueError("pass either pad or pad_pct, not both")
|
|
24
24
|
if pad_pct is not None:
|
|
25
|
-
return
|
|
25
|
+
return round(pad_pct / 100.0 * size)
|
|
26
26
|
if pad is None:
|
|
27
27
|
return 6
|
|
28
28
|
return int(pad)
|
|
@@ -74,12 +74,19 @@ def trace(
|
|
|
74
74
|
)
|
|
75
75
|
|
|
76
76
|
h, w = mask.shape
|
|
77
|
+
offset = pad_px if pad_px > 0 else 0
|
|
77
78
|
work_mask = (
|
|
78
|
-
np.pad(mask, ((
|
|
79
|
+
np.pad(mask, ((offset, offset), (offset, offset)), constant_values=False)
|
|
79
80
|
if pad_px > 0
|
|
80
81
|
else mask
|
|
81
82
|
)
|
|
82
|
-
work_mask =
|
|
83
|
+
work_mask = (
|
|
84
|
+
erode_circular(work_mask, radius=abs(pad_px))
|
|
85
|
+
if pad_px < 0
|
|
86
|
+
else dilate_circular(work_mask, radius=pad_px)
|
|
87
|
+
)
|
|
88
|
+
if not work_mask.any():
|
|
89
|
+
raise EmptyMaskError("padding eroded the foreground to empty")
|
|
83
90
|
work_h, work_w = work_mask.shape
|
|
84
91
|
polygons = trace_mask(work_mask, samples_per_curve=samples_per_curve)
|
|
85
92
|
if not polygons:
|
|
@@ -92,7 +99,7 @@ def trace(
|
|
|
92
99
|
|
|
93
100
|
pts = convex_hull(best) if hull else best
|
|
94
101
|
pts = decimate(pts, max_points)
|
|
95
|
-
pts = normalize(pts, w, h, offset_x=
|
|
102
|
+
pts = normalize(pts, w, h, offset_x=offset, offset_y=offset)
|
|
96
103
|
|
|
97
104
|
if format == "json":
|
|
98
105
|
payload_str = emit(
|
|
@@ -4,7 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
from potrace import Bitmap
|
|
7
|
-
from scipy.ndimage import binary_dilation
|
|
7
|
+
from scipy.ndimage import binary_dilation, binary_erosion
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
def dilate_circular(mask: np.ndarray, *, radius: int) -> np.ndarray:
|
|
@@ -17,6 +17,16 @@ def dilate_circular(mask: np.ndarray, *, radius: int) -> np.ndarray:
|
|
|
17
17
|
return binary_dilation(mask, structure=struct)
|
|
18
18
|
|
|
19
19
|
|
|
20
|
+
def erode_circular(mask: np.ndarray, *, radius: int) -> np.ndarray:
|
|
21
|
+
"""Binary erosion with a circular (Euclidean) structuring element."""
|
|
22
|
+
if radius <= 0:
|
|
23
|
+
return mask
|
|
24
|
+
r = radius
|
|
25
|
+
y, x = np.ogrid[-r : r + 1, -r : r + 1]
|
|
26
|
+
struct = (x * x + y * y) <= r * r
|
|
27
|
+
return binary_erosion(mask, structure=struct)
|
|
28
|
+
|
|
29
|
+
|
|
20
30
|
def flatten_curve(curve, *, samples_per_curve: int) -> list[tuple[float, float]]:
|
|
21
31
|
"""potrace curve → polyline. Beziers are flattened at fixed sample count."""
|
|
22
32
|
pts: list[tuple[float, float]] = []
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|