Skip to main content

A toolkit for processing the ASM's Mammal Image Library (MIL).

Project description

mil-kit

Tests GitHub Tag PyPI - Version

A Python toolkit for batch processing images, with a focus on PSD to image conversion and robust watermarking capabilities.

Features

  • Two main commands: export and watermark.
  • 🚀 Batch process multiple files in a directory.
  • ⚡ Parallel processing for faster execution.
  • 📊 Progress bar with detailed status.
  • 📁 Support for recursive directory processing.
  • ⚡ Preserve folder structure in output.
  • 📝 export: Automatically hide all text layers in PSD files.
  • 🖼️ export: Export processed files as PNG (default) or other formats.
  • 💧 watermark: Apply copyright watermarks to images.
  • 📖 watermark: Metadata-driven watermarks from Excel/CSV files.
  • fallback watermark: Use static text when no metadata match is found.
  • 🎨 watermark: Customize watermark opacity.

Installation

Install using pip:

pip install mil-kit

Or using uv:

uv add mil-kit

Usage

Command Line

mil-kit provides two main commands: export and watermark.

export

Batch hide text layers in PSDs and export them as images.

mil-kit export -d /path/to/psd/files

Process recursively, specify an output directory, and use JPEG format:

mil-kit export -d /path/to/psd/files -o /path/to/output -r -f jpeg --max-resolution 500

watermark

Apply a copyright watermark to a directory of images.

Apply a static watermark to all images:

mil-kit watermark -d /path/to/images -t "© 2024 Your Name"

Use a metadata file to apply dynamic watermarks. The file stem (e.g., 123 from 123.jpg) is matched against the MIL# column in the metadata file.

mil-kit watermark -d /path/to/images --meta-file /path/to/metadata.csv

Use a metadata file with a fallback watermark for images with no match:

mil-kit watermark -d /path/to/images --meta-file /path/to/metadata.csv -t "Default Watermark" --opacity 0.5

Options

Common Options (for export and watermark)

  • -d, --dir: Input directory containing image files (required).
  • -o, --output: Output directory for processed files (default: input directory).
  • -f, --output-format: Output image format (default: png).
  • -r, --recursive: Process subdirectories recursively.
  • --max-resolution: Set maximum resolution for output images.
  • --limit: Limit the number of files to process.
  • --max-workers: Maximum number of parallel workers (default: CPU count).
  • --log-file: Path to a log file.
  • --no-overwrite: Skip files that already exist in the output directory.
  • --quiet: Suppress detailed progress output.

watermark Specific Options

  • -m, --meta-file: Path to an Excel or CSV metadata file.
  • -t, --text: Static fallback watermark text.
  • --opacity: Watermark opacity between 0.0 and 1.0 (default: 0.8).

Python API

You can also use mil-kit as a Python library.

PSDProcessor

from mil_kit.psd.processor import PSDProcessor
from mil_kit.psd.batch import BatchJob

# Process a single file
processor = PSDProcessor("image.psd")
processor.load()
processor.hide_non_image_layers()
processor.export("output.jpg", format="jpeg")

# If you want to export with max resolution
processor.export("output_resized.jpg", format="jpeg", max_resolution=500)

# Batch process
job = BatchJob(
    input_dir="./psd_files",
    output_dir="./output",
    recursive=True,
    output_format="png",
    max_workers=4
)
job.run()

WatermarkProcessor

from mil_kit.watermark.add import WatermarkProcessor
from mil_kit.watermark.batch import WatermarkJob

# Process a single file
processor = WatermarkProcessor("photo.png", watermark_text="2024 Studio Name", opacity=0.8)
processor.load()
processor.apply_text_watermark()
processor.export("output/photo.png", format="png", max_resolution=1920)

# Batch process
job = WatermarkJob(
    input_dir="images",
    meta_file="metadata.csv",
    watermark_text="Default Watermark",
    output_dir="watermarked_output",
)
job.run()

Requirements

  • Python >= 3.10
  • fastexcel >= 0.19.0
  • pillow >= 12.0.0
  • polars >= 1.38.1
  • psd-tools >= 1.12.0
  • tqdm >= 4.67.1

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Issues

Report bugs and request features on GitHub Issues.

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

mil_kit-0.9.1.tar.gz (88.8 kB view details)

Uploaded Source

Built Distribution

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

mil_kit-0.9.1-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file mil_kit-0.9.1.tar.gz.

File metadata

  • Download URL: mil_kit-0.9.1.tar.gz
  • Upload date:
  • Size: 88.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mil_kit-0.9.1.tar.gz
Algorithm Hash digest
SHA256 2046c9405342e38c8edccc3f9e77b07f205d1db62744596f848ea6e46e899faf
MD5 1aaef456b440632aaf820eea6c2d681e
BLAKE2b-256 c288e965903e4e0ac37a2931263d4ec5a6ca7d7399288d70b5adbcc335c91cca

See more details on using hashes here.

File details

Details for the file mil_kit-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: mil_kit-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 26.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mil_kit-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 69c9a2324a7636919190fab77a3cfee2194c4242a08a16bc8cb9f8f49b79834b
MD5 10f74f94175ff298c09b1989fe6b3cdc
BLAKE2b-256 d14bad2a3d856834dc7c5a9c69f580531d4195c781fac129c242f766031ae53b

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