ImageKit2
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.
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:
- Download the
imagekit2binary for your OS (Windows/Linux/macOS) from the GitHub Releases Page. - (Optional) Add it to your system
PATHfor 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:
- Download the
imagekit2-serverbinary from the GitHub Releases Page. - 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
MediumorBoldweights 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_DIRfolder.
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
- Fork the repository on GitHub.
- Create a new Feature Branch (
git checkout -b feature/amazing-feature). - Commit your changes.
- Push to the branch and open a Pull Request.
License
This project is licensed under the MIT License.
Metadata
Release files for imagekit2 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| imagekit2-0.1.5-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | PyPy 3.10 | PyPy 3.10 7.3 | Linux glibc 2.17+ ARM64 | Details |
| imagekit2-0.1.5-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | PyPy 3.9 | PyPy 3.9 7.3 | Linux glibc 2.17+ ARM64 | Details |
| imagekit2-0.1.5-cp37-abi3-win_amd64.whl | CPython 3.7 | abi3 | Windows x86-64 | Details |
| imagekit2-0.1.5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.7 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| imagekit2-0.1.5-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.7 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| imagekit2-0.1.5-cp37-abi3-macosx_11_0_arm64.whl | CPython 3.7 | abi3 | macOS 11.0+ ARM64 | Details |
| imagekit2-0.1.5-cp37-abi3-macosx_10_12_x86_64.whl | CPython 3.7 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 21.7 MB
Release files / imagekit2-0.1.5-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | imagekit2-0.1.5-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 3.2 MB |
| Tags | Linux glibc 2.17+ ARM64 PyPy 3.10 PyPy 3.10 7.3 |
|
SHA-256 checksum How to use checksums |
e935f127d60c63c9ead55a16d47b343d6808878740a196fb557ffa7778676b33
|
|
BLAKE2b-256 checksum How to use checksums |
0e01db7c94822aec8e385860a0b382f3e3ce1933db8482dd7b6a9aecd49024ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|
Release files / imagekit2-0.1.5-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | imagekit2-0.1.5-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 3.2 MB |
| Tags | Linux glibc 2.17+ ARM64 PyPy 3.9 PyPy 3.9 7.3 |
|
SHA-256 checksum How to use checksums |
a7e3d0ecf7233e1ba6b1c01f9d8486052005610aaf4aabfe1d8caae6de1d11eb
|
|
BLAKE2b-256 checksum How to use checksums |
2b8637fd6d25ac62f012a48ed4f2dba00a013a0c78b7aa05e0d205572d3c2b65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|
Release files / imagekit2-0.1.5-cp37-abi3-win_amd64.whl
| Download URL | imagekit2-0.1.5-cp37-abi3-win_amd64.whl |
|---|---|
| Size | 2.9 MB |
| Tags | CPython 3.7 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
c21005115b5cbb6a4592415cea422d74bdacd962af7b610aee3fc1e8c2eb3c0f
|
|
BLAKE2b-256 checksum How to use checksums |
a80355eb4024e4f2d56def1ca736d540674fca0d6525fb4a0a85ce35b2512b95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|
Release files / imagekit2-0.1.5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | imagekit2-0.1.5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 3.3 MB |
| Tags | CPython 3.7 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
612e419fbfe6024bf24e9607551984587789bbfeaba2f94308c63cae88148ec6
|
|
BLAKE2b-256 checksum How to use checksums |
5941aba1ac2447dd8e59e1b0b8a76c2f6454cfdbbdae5a38191bc3a24187673e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|
Release files / imagekit2-0.1.5-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | imagekit2-0.1.5-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 3.2 MB |
| Tags | CPython 3.7 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
1e10a723d28d0bc61459f6ed90681740d531f7db013ef881175df00752d452bd
|
|
BLAKE2b-256 checksum How to use checksums |
76e720b11f40fe944908a7e7643fc1ef309cbbfe365d993b97e42e90697afb7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|
Release files / imagekit2-0.1.5-cp37-abi3-macosx_11_0_arm64.whl
| Download URL | imagekit2-0.1.5-cp37-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.0 MB |
| Tags | CPython 3.7 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8c0d8c4484628b89b14208576b35c1baaa750d8377ae56bfd54e7894bd535a9a
|
|
BLAKE2b-256 checksum How to use checksums |
41c48733be4b3249380d61772abf2beb5aa4fa7e700067df75aa51c741e33d85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|
Release files / imagekit2-0.1.5-cp37-abi3-macosx_10_12_x86_64.whl
| Download URL | imagekit2-0.1.5-cp37-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 3.1 MB |
| Tags | CPython 3.7 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
28e433f17696bc9d7b21928b9c90fee569ce6ab0fd3342b3339ee12a37e9256d
|
|
BLAKE2b-256 checksum How to use checksums |
532ac692bd6137fc3a217aafd1c61392bb0f45246af38556d31a795714e5272c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|