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.7.tar.gz (57.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.7-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: twat_image-2.7.7.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

Hashes for twat_image-2.7.7.tar.gz
Algorithm Hash digest
SHA256 abed0fb3cf823b30c81a7df23d83cdda644e9a98f59c5d94c26136c9d1a86c77
MD5 69e6cbb3cb0265c3ee771c66c398308a
BLAKE2b-256 614864c24c7e46bc5b6a47b6610fdc44e8633d546e645a0b6cb56c13a6575704

See more details on using hashes here.

File details

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

File metadata

  • Download URL: twat_image-2.7.7-py3-none-any.whl
  • Upload date:
  • Size: 13.6 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2b157240fc2bb15bb460287a43b6957fa78bb0b0e4d5a1dff7b28e35d2483749
MD5 fb2aa6260bb7cd9991bb92993b3e4f5a
BLAKE2b-256 3d991e6c7c353731d028b3b4aa9a71edb12981a5cb0448508aea6f428f187f86

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