Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twat_image-2.7.9.tar.gz (55.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twat_image-2.7.9-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file twat_image-2.7.9.tar.gz.

File metadata

  • Download URL: twat_image-2.7.9.tar.gz
  • Upload date:
  • Size: 55.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

Hashes for twat_image-2.7.9.tar.gz
Algorithm Hash digest
SHA256 5695582a8aa5da3f7e2e55766b0f3874a00834034ce259816fbb75fa590184de
MD5 5ff9da03ce322ed8fd95aa3fcd3f7f37
BLAKE2b-256 002faddc99d18209f5f45ac5cbd5523c102770b89b1ebb8de569bef12424a1b5

See more details on using hashes here.

File details

Details for the file twat_image-2.7.9-py3-none-any.whl.

File metadata

  • Download URL: twat_image-2.7.9-py3-none-any.whl
  • Upload date:
  • Size: 14.1 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

Hashes for twat_image-2.7.9-py3-none-any.whl
Algorithm Hash digest
SHA256 174ac76218f1f66d93e9b42ea70c2658515d8e62bb623382213aabc14a36a933
MD5 2dfdb5a741203ee4dd8e7cebd1bbdfa0
BLAKE2b-256 23f698f33c8c31b98acc79c61f5ef743e69c3beebcfe4f7daf8a06d4c7bd064f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page