Skip to content

Background removal (rembg + OpenCV fallback) - Smart background detection & blending - Smart cropping (object-aware) - Auto color correction - Resize & compress to target file size - Optional AI upscaling (Real-ESRGAN integration) - Batch processing, caching, CLI & FastAPI

License

Notifications You must be signed in to change notification settings

alok-kumar8765/image_tool

Repository files navigation

Image Tools

A complete image processing toolkit built by Alok Kumar Kaushal
GitHub: https://github.com/alok-kumar8765

Features

✔ Background removal
✔ Add solid/background color
✔ Resize
✔ Compress (maintain quality)
✔ Enhance (sharpness, contrast, brightness)
✔ Batch processing
✔ Caching
✔ CLI Tool
✔ FastAPI API
✔ AI Upscaling (optional)

Install

  • pip install image_tools



Install optional AI modules


  • pip install image_tools[ai]


### CLI Usage


  • image-tools remove-bg in.png out.png

  • image-tools compress in.jpg out.jpg --kb 80


### Start API

  • uvicorn image_tools.api:app --reload


💻 CLI Tool (Command-Line Interface)

  • Users can run commands like:

image-tools remove-bg input.jpg output.png  
image-tools add-bg input.png output.jpg --color "#ffffff"
image-tools enhance input.jpg output.jpg --sharpness 1.7 --contrast 1.4
image-tools compress input.jpg output.jpg --target-kb 100
image-tools resize input.jpg output.jpg --width 800 --height 600
image-tools batch process-dir/ output-dir/ --compress 100

  • CLI should parse arguments (use argparse or click), handle errors, print helpful messages.

🌐 API Version (FastAPI wrapper) — for SaaS or web use

  • A REST API with endpoints such as:

POST /remove-bg  → upload image, returns processed image  
POST /process   → accept a JSON specifying operations (remove_bg, resize, compress, enhance, etc.) + image → returns processed image  

  • Use asynchronous processing for better throughput. Using FastAPI and optionally background tasks. This enables easy integration in other projects, or exposing as an internal microservice.

  • Optionally, support authentication / rate-limiting / file size limits / concurrency controls — important for production usage.

  • This approach is used in real-world open-source tools built with Python + FastAPI.


🔄 Batch Processing & Caching

  • Batch-processing: ability to process entire folder (or list of files) together — e.g. convert + compress many product photos at once. Use multiprocessing or multithreading for speed; maybe even allow a "dry-run" mode.

  • Caching: compute a hash (e.g. SHA256) of input file + operations parameters; store output in cache dir. If the same image + operations requested again — return cached output instead of reprocessing. Helps a lot when dealing with many repeated edits (e.g. product catalogs).


🧪 Unit Tests (pytest)

  • For each function (remove_bg, add_background, resize, compress, enhance), write tests to check: valid image, bad path, invalid parameters, edge cases (tiny images, large images, already small file size, transparent PNGs, etc.).

  • For batch / cache / CLI / API — tests for correct behavior, error handling, concurrency, etc.


🧠 AI Upscaling Integration (Real-ESRGAN)

  • Provide optional module ai_upscale.py — if user installed extras (torch, real-esrgan), then allow deep-learning–based upscaling / enhancement rather than traditional interpolation-based resize. Real-ESRGAN is known to produce much better detail, sharper images, and reduce artifacts compared to classical methods.

  • Also support GPU acceleration (if available), but fallback to CPU if not — with warning.

  • Provide options: 2×, 4× upscaling, denoising, detail enhancement, choose between different pre-trained models (photo / illustration / anime) if supported.


About

Background removal (rembg + OpenCV fallback) - Smart background detection & blending - Smart cropping (object-aware) - Auto color correction - Resize & compress to target file size - Optional AI upscaling (Real-ESRGAN integration) - Batch processing, caching, CLI & FastAPI

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published