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.
Metadata
Release files for posterize 2.11.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| posterize-2.11.0.tar.gz | 126.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| posterize-2.11.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 255.5 kB
Release files / posterize-2.11.0.tar.gz
| Download URL | posterize-2.11.0.tar.gz |
|---|---|
| Size | 126.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf5ed6cad2258dced4fd8d5aaa819f1f030d081da54b8a06d05e22ac2c0b6673
|
|
BLAKE2b-256 checksum How to use checksums |
f55b89ed7bfa9cdb2d83efce5a5634b946c89b54eab207d5a8d5de593cd05ad9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.4
|
Release files / posterize-2.11.0-py3-none-any.whl
| Download URL | posterize-2.11.0-py3-none-any.whl |
|---|---|
| Size | 129.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c0be0108ab9a39a0ffaa53bd59cae1168069d015fd2eb1e4b1cf77bd51dda68f
|
|
BLAKE2b-256 checksum How to use checksums |
dc7a3122f15177430cc2421d8b1137071e67f529244d8ce9c8358d40a221d1e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.4
|