Skip to content

Latest commit

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Python Image Optimization

Demo app for the blog post: Python Image Optimization with ImageKit.

Backend Python companion to the Next.js image and video optimization demos. Demonstrates resize, compression, modern format delivery, smart cropping, and AI transformations using the imagekitio Python SDK and Flask. Every section shows the Python code, the generated URL, and the resulting image with real file sizes.

What's on the page

SectionWhat it shows
Summary table5-variant comparison including format, size, and savings %
01 — SDK setupInstall + initialize code
02 — External storageConnect S3/GCS or upload via SDK
03 — Raw baselineUnoptimized source via ?tr=orig-true
04 — ImageKit defaultAuto format (AVIF/WebP) + default compression
05 — Resizewidth: 800 with size comparison
06 — Compression4 quality levels + interactive quality slider
07 — Responsive imagesbuild_srcset() helper + live viewport indicator
08 — Smart cropFace crop, auto crop, object-aware crop (dog/cat)
09 — AI background removale-bgremove transformation
10 — AI generative fillbg-genfill with optional prompt input

Quick start

  1. Clone the repo and navigate to this folder:

    cd python-image-optimization
  2. Create a virtual environment and install dependencies:

    python3 -m venv venv
    source venv/bin/activate # or venv\Scripts\activate on Windows
    pip install -r requirements.txt
  3. Copy the env example and edit if needed:

    cp .env.example .env

    The defaults use the public ikmedia account

  4. Start the server:

    python app.py

    Open http://localhost:5000.

Environment variables

VariableDescription
IMAGEKIT_URL_ENDPOINTYour ImageKit URL endpoint, e.g. https://ik.imagekit.io/your_imagekit_id
IMAGEKIT_PUBLIC_KEYYour public key
IMAGEKIT_PRIVATE_KEYYour private key

Customization

To use different source images, update the paths in lib/images.py. The images should be accessible via your ImageKit URL endpoint.

Related

About

Python image optimization examples using the ImageKit Python SDK

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages