Skip to main content

twat-image

CI PyPI Python 3.10+ License: MIT

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.

Documentation · Changelog · Issues

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.

Metadata

Release files for twat-image 2.7.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for twat-image 2.7.11
File Size Uploaded Provenance Actions
twat_image-2.7.11.tar.gz 1.1 MB With provenance Details for twat_image-2.7.11.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for twat-image 2.7.11
File Interpreter ABI Platform Actions
twat_image-2.7.11-py3-none-any.whl Python 3 none any Details for twat_image-2.7.11-py3-none-any.whl

Total release size: 1.1 MB

Release files / twat_image-2.7.11.tar.gz

Download URL twat_image-2.7.11.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
7e21e6d7d01d30c3d88486ab9240c25b6f2b8029518ac26c79d320b853b69699
BLAKE2b-256 checksum
How to use checksums
32af775fc99f5fe9fe236c3e068fac4c1c49599a0eecdf6e96c8bc0976f21a99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / twat_image-2.7.11-py3-none-any.whl

Download URL twat_image-2.7.11-py3-none-any.whl
Size 14.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b7552d81152ee41396bce1547d22704a33413663367e24973a0507e972b845ef
BLAKE2b-256 checksum
How to use checksums
56ff8fe78b8804085136112fd899b933bec5c3032310b0075f0db9fefe497e48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for twat-image 2.7.11

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for twat_image-2.7.11.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page