ipolypad 1.0.1__tar.gz → 1.0.2__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.1 → ipolypad-1.0.2}/PKG-INFO +1 -1
- {ipolypad-1.0.1 → ipolypad-1.0.2}/src/ipolypad/__version__.py +2 -2
- {ipolypad-1.0.1 → ipolypad-1.0.2}/src/ipolypad/emit.py +1 -1
- {ipolypad-1.0.1 → ipolypad-1.0.2}/src/ipolypad/pipeline.py +12 -4
- {ipolypad-1.0.1 → ipolypad-1.0.2}/src/ipolypad/simplify.py +10 -3
- {ipolypad-1.0.1 → ipolypad-1.0.2}/.gitignore +0 -0
- {ipolypad-1.0.1 → ipolypad-1.0.2}/README.md +0 -0
- {ipolypad-1.0.1 → ipolypad-1.0.2}/pyproject.toml +0 -0
- {ipolypad-1.0.1 → ipolypad-1.0.2}/src/ipolypad/__init__.py +0 -0
- {ipolypad-1.0.1 → ipolypad-1.0.2}/src/ipolypad/__main__.py +0 -0
- {ipolypad-1.0.1 → ipolypad-1.0.2}/src/ipolypad/color.py +0 -0
- {ipolypad-1.0.1 → ipolypad-1.0.2}/src/ipolypad/errors.py +0 -0
- {ipolypad-1.0.1 → ipolypad-1.0.2}/src/ipolypad/fetch.py +0 -0
- {ipolypad-1.0.1 → ipolypad-1.0.2}/src/ipolypad/rasterize.py +0 -0
- {ipolypad-1.0.1 → ipolypad-1.0.2}/src/ipolypad/trace.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.2
|
|
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/
|
|
@@ -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.2'
|
|
22
|
+
__version_tuple__ = version_tuple = (1, 0, 2)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -133,7 +133,7 @@ def to_html(
|
|
|
133
133
|
body {{ font-family: -apple-system, system-ui, sans-serif; padding: 24px; background: #f6f7f9; }}
|
|
134
134
|
.stage {{ position: relative; width: {width}px; height: {height}px; }}
|
|
135
135
|
.stage img {{ position: absolute; inset: 0; width: 100%; height: 100%; }}
|
|
136
|
-
.stage svg {{ position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }}
|
|
136
|
+
.stage svg {{ position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }}
|
|
137
137
|
code {{ display: block; white-space: pre-wrap; background: #fff; padding: 12px; border: 1px solid #e2e6ec; border-radius: 6px; }}
|
|
138
138
|
</style>
|
|
139
139
|
</head>
|
|
@@ -5,6 +5,8 @@ from __future__ import annotations
|
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
from typing import Any, Literal
|
|
7
7
|
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
8
10
|
from .color import autoenhance, mask_fixed, mask_smart
|
|
9
11
|
from .emit import emit
|
|
10
12
|
from .errors import EmptyMaskError, OnlyFrameError, TraceEmptyError
|
|
@@ -71,20 +73,26 @@ def trace(
|
|
|
71
73
|
"no foreground above threshold; lower --bg-tolerance or check source"
|
|
72
74
|
)
|
|
73
75
|
|
|
74
|
-
mask = dilate_circular(mask, radius=pad_px)
|
|
75
76
|
h, w = mask.shape
|
|
76
|
-
|
|
77
|
+
work_mask = (
|
|
78
|
+
np.pad(mask, ((pad_px, pad_px), (pad_px, pad_px)), constant_values=False)
|
|
79
|
+
if pad_px > 0
|
|
80
|
+
else mask
|
|
81
|
+
)
|
|
82
|
+
work_mask = dilate_circular(work_mask, radius=pad_px)
|
|
83
|
+
work_h, work_w = work_mask.shape
|
|
84
|
+
polygons = trace_mask(work_mask, samples_per_curve=samples_per_curve)
|
|
77
85
|
if not polygons:
|
|
78
86
|
raise TraceEmptyError("potrace produced no curves")
|
|
79
87
|
|
|
80
|
-
canvas_area = float(
|
|
88
|
+
canvas_area = float(work_h * work_w)
|
|
81
89
|
best = pick_outer_shell(polygons, canvas_area=canvas_area)
|
|
82
90
|
if best is None:
|
|
83
91
|
raise OnlyFrameError("only the bitmap-frame curve was traced")
|
|
84
92
|
|
|
85
93
|
pts = convex_hull(best) if hull else best
|
|
86
94
|
pts = decimate(pts, max_points)
|
|
87
|
-
pts = normalize(pts, w, h)
|
|
95
|
+
pts = normalize(pts, w, h, offset_x=pad_px, offset_y=pad_px)
|
|
88
96
|
|
|
89
97
|
if format == "json":
|
|
90
98
|
payload_str = emit(
|
|
@@ -99,6 +99,13 @@ def decimate(pts: list[Point], max_points: int) -> list[Point]:
|
|
|
99
99
|
return rdp(pts, hi)
|
|
100
100
|
|
|
101
101
|
|
|
102
|
-
def normalize(
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
def normalize(
|
|
103
|
+
pts: list[Point],
|
|
104
|
+
width: int,
|
|
105
|
+
height: int,
|
|
106
|
+
*,
|
|
107
|
+
offset_x: float = 0.0,
|
|
108
|
+
offset_y: float = 0.0,
|
|
109
|
+
) -> list[Point]:
|
|
110
|
+
"""Normalize over the original image box, optionally undoing work-canvas offset."""
|
|
111
|
+
return [((x - offset_x) / width, (y - offset_y) / height) for (x, y) in pts]
|
|
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
|