Posterize an image with stacked SVG geometry (generated by Potrace).
Project description
Posterize
Posterize an image with stacked SVG geometry (generated by Potrace).
API
The package exposes four main functions and two result types:
-
posterize(image_path, num_cols, *, savings_weight=None, vibrant_weight=None, max_dim=None)Load an image from disk and posterize it. Returns aPosterization.image_path: path to the image.num_cols: number of colors (layers) in the result; fewer may be returned if colors are exhausted.savings_weight: weight for sum savings vs average savings when choosing layer colors (default 0.25).vibrant_weight: bias toward more vibrant colors, 0–1 (default 0).max_dim: if set, resize the image so its longer side is at most this many pixels before processing. -
posterize_mono(pixels, num_cols, *, savings_weight=None, vibrant_weight=None)Posterize a grayscale pixel array. Returns aPosterization.pixels:(r, c)uint8 array (e.g. one channel of an image).num_cols,savings_weight,vibrant_weight: same asposterize. -
new_target_image(path, max_dim=None)Quantize an image file to at most 512 colors and return aTargetImage(palette, indices, cost matrix). Used internally byposterize; useful if you need the quantized image without building layers.path: path to an image file.max_dim: maximum width or height; image is thumbnailed if larger (default 500). -
new_target_image_mono(pixels)Quantize a grayscale(r, c)uint8 array to at most 256 colors. Returns aTargetImage. Used internally byposterize_mono.
Result types: Posterization (from posterize / posterize_mono) has .write_svg(path, num_cols=None) and methods for layers, colors, and SVG elements. TargetImage holds the quantized palette, indices, and cost matrix for layer-building.
Example
from posterize import posterize
posterized = posterize("image.png", 4)
posterized.write_svg("output.svg")
Caching
-
.cache_posterize(in the current working directory) Memoizesposterize()andposterize_mono()by their arguments. Repeated calls with the same inputs return the cachedPosterizationwithout recomputing layers. -
.cache_quantize(in the current working directory) Memoizes quantized image data:quantize_image()/quantize_rgba()andquantize_mono(). Used bynew_target_image()andnew_target_image_mono(), and indirectly byposterize()andposterize_mono(). -
Temp directory (
paths.CACHE_DIR, under the system temp dir ascluster_colors_cache) Used while generating SVG paths: a temporary BMP and Potrace-generated SVG are written here duringlayer_to_svgd()and then removed. No long-lived cache.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file posterize-2.10.0.tar.gz.
File metadata
- Download URL: posterize-2.10.0.tar.gz
- Upload date:
- Size: 126.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c625f3cc4bae90ca2f8638515b811f8f08592b546d353d559adf824134da5fb6
|
|
| MD5 |
1253ad884a4a358dda80af179801a719
|
|
| BLAKE2b-256 |
07f7703172bc223487b86d3dc54dc6a43acc799465f3def5527834262643613a
|
File details
Details for the file posterize-2.10.0-py3-none-any.whl.
File metadata
- Download URL: posterize-2.10.0-py3-none-any.whl
- Upload date:
- Size: 128.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49025963b2cfae7192ec1e48599f2185c3eb03c6326437161e5bfe42e54d260b
|
|
| MD5 |
a0484f6ad5032ea435bd30f17d6cab89
|
|
| BLAKE2b-256 |
a71ed81a0b98264a0d7f98e469d4d5fb28de2871893a8b13f30f0960f74eb2a3
|