Skip to main content

A high-performance, Rust-powered image watermarking library. Supports text and logo watermarks, smart contrast, tiling, rotation, and precise positioning.

Project description

ImageKit2

PyPI version License: MIT

ImageKit2 is a high-performance image watermarking engine built with Rust. It is designed for speed, memory safety, and professional typography rendering.

[!IMPORTANT] Migration Notice: This is the successor to the original imagekit, featuring a completely rewritten core for superior performance and modern text styling (shadows, alignment, smart contrast).

中文文档

✨ Why ImageKit2?

ImageKit2 is not just a wrapper around an image library; it is a purpose-built engine designed for high-quality watermarking tasks.

  • 🚀 Blazing Fast & Memory Safe Built completely in Rust, ImageKit2 offers superior performance and memory safety compared to pure Python solutions (like Pillow), especially when processing large batches or high-resolution images.

  • 🧠 Smart Contrast (Auto Color) Stop worrying about watermarks being invisible on dark or bright backgrounds. Use color="auto", and the engine will calculate the background luminance to automatically switch between black and white text.

  • 🎨 Professional Typography Go beyond simple text drawing. ImageKit2 supports:

    • Drop Shadows for better readability.
    • Faux Bold (Stroke) to make thin fonts stand out.
    • Multi-line Alignment (Left/Center/Right).
    • Smart Padding to prevent text clipping.
  • 🛡️ Production Ready

    • EXIF Correction: Automatically rotates images based on orientation tags.
    • Thread-Safe: Font loaders and processing pipelines are designed for concurrent environments (e.g., multi-threaded Python web servers).
    • Modern Formats: Full support for WebP, AVIF, JPEG, and PNG.
  • 🧩 One Core, Three Interfaces Whether you need a Python SDK for your app, a CLI for your scripts, or a REST API Server for your microservices, ImageKit2 has you covered with a unified feature set.

Demo Watermark


Choose Your Usage Scenario

ImageKit2 adapts to your workflow. Whether you are building a Python app, running batch scripts, or deploying a microservice, pick the method that fits your needs.

Scenario 1: Python Application Integration

Best for: Data science pipelines, Django/FastAPI apps, in-memory processing.

Installation:

pip install imagekit2

Usage Example:

import imagekit2

# 1. Initialize (Point to your font files for best results)
# The library will search these paths/files for fonts.
wk = imagekit2.Watermarker(["/Library/Fonts/Arial.ttf", "./assets/fonts"])

# 2. Process
with open("input.jpg", "rb") as f:
    img_bytes = f.read()

processed_bytes = wk.process(
    img_bytes,
    text="Clean Watermark",
    position="br",
    padding=20,
    size=32.0,
    color="#FFFFFF",
    opacity=0.9,
    # Tip: Set stroke to 0 for crisp, modern text.
    stroke_width=0,
    # Add depth with shadows
    shadow_x=2,
    shadow_y=2,
    shadow_color="#00000080"
)

# 3. Save
with open("output.png", "wb") as f:
    f.write(processed_bytes)

Scenario 2: Local Batch Processing (CLI)

Best for: DevOps tasks, shell scripts, processing folders of images.

Installation:

  1. Download the imagekit2 binary for your OS (Windows/Linux/macOS) from the GitHub Releases Page.
  2. (Optional) Add it to your system PATH for global access.

Usage Example:

# Assuming the binary is in your current folder
./imagekit2 \
  --input "./input.jpg" \
  --output "./output.jpg" \
  --text "Copyright 2024" \
  --position "center" \
  --size 40 \
  --font "/Library/Fonts/Arial.ttf" \
  --color "#FFFFFF" \
  --shadow-x 2 \
  --shadow-y 2

Scenario 3: HTTP Microservice

Best for: Cloud deployment, decoupling image processing from main logic.

Installation & Start:

  1. Download the imagekit2-server binary from the GitHub Releases Page.
  2. Grant execution permissions (Linux/macOS): chmod +x imagekit2-server

Running the Server:

# Set font directory (Optional, defaults to ./assets/fonts)
export FONT_DIR="./assets/fonts"

# Start server (Listens on port 3000)
./imagekit2-server

API Contract:

  • Endpoint: POST /process
  • Content-Type: multipart/form-data
  • Payload:
    • file: The image file.
    • params: JSON string (e.g., {"mode": "text", "text": "Hello", "size": 30}).

Example (cURL):

curl -X POST http://localhost:3000/process \
  -F "file=@input.jpg" \
  -F "params={\"mode\":\"text\",\"text\":\"API Test\",\"position\":\"br\",\"shadow_x\":2}" \
  --output result.jpg

Font Configuration (Recommended)

1. Default (Latin/English Support)

If your watermark text consists only of Latin characters (English, Numbers, Punctuation), you do not need to configure a font.

ImageKit2 embeds Inter Regular (Inter_24pt-Regular.ttf) by default—a high-quality, modern sans-serif font that looks professional out of the box.

2. Custom Fonts (Required for CJK / Styling)

You MUST provide a custom font file (.ttf / .otf) in the following cases:

  • Non-Latin Characters: If your text contains Chinese, Japanese, Korean (CJK), or other non-Latin characters (the default Inter font does not contain these glyphs).
  • Specific Styles: If you need a Bold, Italic, or Serif look (e.g., Roboto-Bold.ttf).

Where to get fonts?

  • Google Fonts: A massive collection of free fonts.
    • Recommendations: Roboto, Open Sans, Montserrat, or Lato.
    • Tip: Download the Medium or Bold weights for better visibility on images.

How to load a custom font:

  • Python: Watermarker(["/path/to/YourFont-Bold.ttf"])
  • CLI: --font "/path/to/YourFont-Bold.ttf"
  • Server: Place the file in the FONT_DIR folder.

Appendix: Parameter Reference

1. Common Parameters (Text & Logo)

Parameter Default Description
position br tl, tr, bl, br, center, tile, or manual coords.
padding 20 Distance from the edge (pixels).
opacity 0.8 0.0 to 1.0.
angle 0.0 Rotation angle in degrees.
resize_width None Resize input width before processing.
output_format png jpg, png, webp, etc.
quality 80 Compression quality (1-100).

2. Text Parameters

Parameter Default Description
text - The watermark content.
size 24.0 Font size in pixels.
color #FFFFFF Hex color. Use "auto" for smart contrast.
align left left, center, right.
stroke_width 0 Outline width. Keep 0 for clean modern style.
stroke_color #000000 Outline color.
shadow_x 0 Horizontal shadow offset.
shadow_y 0 Vertical shadow offset.
shadow_color #000000 Shadow color (supports alpha).

3. Logo Parameters

Parameter Default Description
logo - The source image path/bytes.
scale None Scale relative to background width (e.g., 0.1 = 10%).

Development & Contribution

We welcome contributions! Whether it's fixing bugs, adding features, or improving documentation, here's how to set up your environment.

1. Prerequisites

  • Rust: Install via rustup.rs (Stable channel).
  • Python: Version 3.8+ (Required for building bindings).
  • Maturin: Required for compiling the Python extension (pip install maturin).

2. Build the Workspace

This project is organized as a Cargo workspace containing core, cli, server, and bindings/python.

# Clone the repository
git clone https://github.com/hzbd/imagekit2.git
cd imagekit2

# Build Core, CLI, and Server
cargo build --workspace

# Run tests (Core logic)
cargo test --workspace

3. Developing Python Bindings

To test changes in the Python SDK, you need to build the wheel locally using maturin.

# Navigate to the bindings directory (Optional, or run from root with -m)
# Recommended: Create a virtual environment first
python -m venv .venv
source .venv/bin/activate

# Build and install into the current environment
maturin develop -m bindings/python/Cargo.toml --release

4. Contribution Workflow

  1. Fork the repository on GitHub.
  2. Create a new Feature Branch (git checkout -b feature/amazing-feature).
  3. Commit your changes.
  4. Push to the branch and open a Pull Request.

License

This project is licensed under the MIT License.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

imagekit2-0.1.5-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.2 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

imagekit2-0.1.5-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.2 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

imagekit2-0.1.5-cp37-abi3-win_amd64.whl (2.9 MB view details)

Uploaded CPython 3.7+Windows x86-64

imagekit2-0.1.5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ x86-64

imagekit2-0.1.5-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.2 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.17+ ARM64

imagekit2-0.1.5-cp37-abi3-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

imagekit2-0.1.5-cp37-abi3-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

Details for the file imagekit2-0.1.5-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for imagekit2-0.1.5-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e935f127d60c63c9ead55a16d47b343d6808878740a196fb557ffa7778676b33
MD5 1d0025a62ef494cd6e82a80e92895041
BLAKE2b-256 0e01db7c94822aec8e385860a0b382f3e3ce1933db8482dd7b6a9aecd49024ba

See more details on using hashes here.

File details

Details for the file imagekit2-0.1.5-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for imagekit2-0.1.5-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a7e3d0ecf7233e1ba6b1c01f9d8486052005610aaf4aabfe1d8caae6de1d11eb
MD5 d6f57efccf59a9f66d3140fd7f2f2589
BLAKE2b-256 2b8637fd6d25ac62f012a48ed4f2dba00a013a0c78b7aa05e0d205572d3c2b65

See more details on using hashes here.

File details

Details for the file imagekit2-0.1.5-cp37-abi3-win_amd64.whl.

File metadata

  • Download URL: imagekit2-0.1.5-cp37-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: CPython 3.7+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for imagekit2-0.1.5-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c21005115b5cbb6a4592415cea422d74bdacd962af7b610aee3fc1e8c2eb3c0f
MD5 6d3665bbdef887094184e439cb052723
BLAKE2b-256 a80355eb4024e4f2d56def1ca736d540674fca0d6525fb4a0a85ce35b2512b95

See more details on using hashes here.

File details

Details for the file imagekit2-0.1.5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for imagekit2-0.1.5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 612e419fbfe6024bf24e9607551984587789bbfeaba2f94308c63cae88148ec6
MD5 7b5dc809494eb55a1306079c1372ad4e
BLAKE2b-256 5941aba1ac2447dd8e59e1b0b8a76c2f6454cfdbbdae5a38191bc3a24187673e

See more details on using hashes here.

File details

Details for the file imagekit2-0.1.5-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for imagekit2-0.1.5-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1e10a723d28d0bc61459f6ed90681740d531f7db013ef881175df00752d452bd
MD5 ab5fd5929edafdb76099044087b30100
BLAKE2b-256 76e720b11f40fe944908a7e7643fc1ef309cbbfe365d993b97e42e90697afb7f

See more details on using hashes here.

File details

Details for the file imagekit2-0.1.5-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for imagekit2-0.1.5-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8c0d8c4484628b89b14208576b35c1baaa750d8377ae56bfd54e7894bd535a9a
MD5 8e08f2b74994cc9b39c9449f2ea05b9a
BLAKE2b-256 41c48733be4b3249380d61772abf2beb5aa4fa7e700067df75aa51c741e33d85

See more details on using hashes here.

File details

Details for the file imagekit2-0.1.5-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for imagekit2-0.1.5-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 28e433f17696bc9d7b21928b9c90fee569ce6ab0fd3342b3339ee12a37e9256d
MD5 064e158056fc214988821ab7a276bce6
BLAKE2b-256 532ac692bd6137fc3a217aafd1c61392bb0f45246af38556d31a795714e5272c

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