A Python utility for converting images to include alpha channels based on grayscale values, and other image manipulations.
Project description
twat-image
twat-image is the image domain package for the twat plugin ecosystem. It owns deterministic image operations and delegates AI generation or editing to twat_genai when that optional package is installed.
Install
pip install twat-image
For development:
pip install -e ".[test,dev]"
Python API
from PIL import Image
from twat_image import igray2alpha, scale_image, read_image_metadata
image = Image.open("logo.png")
mask = igray2alpha(image, color="black", white_point=0.9, black_point=0.1)
mask.save("logo-alpha.png")
small = scale_image(image, width=512)
small.save("logo-512.png")
print(read_image_metadata("logo.png"))
Deterministic helpers include:
igray2alpha/gray2alpha: grayscale-derived alpha masks.alpha_from_diff: alpha from the grayscale difference of two images.normalize_image: auto-contrast and optional equalization.scale_image,crop_image,outcrop_image: basic geometry.convert_image: format conversion through Pillow.read_image_metadata,find_duplicate_images: dimensions, format, and average-hash duplicate grouping.
CLI
python -m twat_image --help
python -m twat_image gray2alpha input.jpg output.png --color black
python -m twat_image scale input.png output.png --width 512
python -m twat_image crop input.png crop.png 10 10 300 300
python -m twat_image outcrop input.png padded.png --left 40 --right 40 --top 20 --bottom 20
python -m twat_image normalize input.png normalized.png
python -m twat_image metadata input.png
The legacy imagealpha script remains as a compatibility alias for the original grayscale-to-alpha command.
AI image boundary
twat-image does not contain provider clients. Use generate_image() and edit_image() as thin adapters to twat_genai:
from twat_image import generate_image, edit_image
generate_image("a black cat drawn as clean vector art", output_dir="out")
edit_image("make it look like ink on paper", "input.png", output_dir="out")
Install and configure twat-genai separately for OpenAI, Gemini/Nano Banana, Fal, or future provider engines.
Reference scripts
Reusable deterministic work from reference/bin-img-vid/imggray2alpha, imgalphafromdiff.py, imgscale.py, imgcrop, imgoutcrop, and imgdedup is represented by the APIs above. Provider-heavy scripts such as imgquotio.py and imgnanobanatrans.py belong in twat_genai; this package only calls that boundary.
Local shell workflow glue remains in reference/bin-img-vid/ because it encodes workstation-specific pipelines rather than reusable library behavior.
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 twat_image-2.7.8.tar.gz.
File metadata
- Download URL: twat_image-2.7.8.tar.gz
- Upload date:
- Size: 57.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e29a1ccc7dac41893961f861e69355e9154d7d75ac4c77f54d2fb5969d5be22
|
|
| MD5 |
e557f09530e204cdf0765a1660ab22de
|
|
| BLAKE2b-256 |
ab79fd252bbb5af37b693e328b5f11dedb6f7e60b2cd83ea914c8302f9b690fa
|
File details
Details for the file twat_image-2.7.8-py3-none-any.whl.
File metadata
- Download URL: twat_image-2.7.8-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81c9cbcd4c1623c426ecd415c49040fa3290b1106b990eb0f964fb4e96e99214
|
|
| MD5 |
7fe1ba45c627df5dfca34b4c41b657a5
|
|
| BLAKE2b-256 |
dfc828fe8c609b130936f3c6795b018d8a074cec70076ed13600df681f63ae6a
|