Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🖼️ Image Compressor — Lossless PNG to WebP

Deploy with Vercel Python Pillow License: MIT

Pixel-perfect PNG → WebP compression under 400 bytes. Powered by Python Pillow with SHA-256 pixel verification. Built for TDS exam submissions.


✨ Features

Feature Description
🎯 Lossless Compression PNG → WebP with zero pixel loss, verified by SHA-256 hash comparison
📦 < 400 Bytes Output Compressed files consistently under 400 bytes for exam compliance
🐍 Python Pillow Backend Server-side compression using lossless=True, quality=100
Instant Processing ~30ms compression via Vercel serverless functions
🔒 Pixel Verification SHA-256 hash of raw pixel data — before and after — proves lossless
📱 Responsive Design Dark glassmorphism UI that works on desktop and mobile
🔄 Auto Retry 2 automatic retries with exponential backoff on network failures
📥 Smart Download Files download with original name + _by_GauravTomar.webp branding

🚀 Live Demo

→ Try it live on Vercel (deploy your own below)


🛠️ Tech Stack

Layer Technology
Frontend Vanilla HTML, CSS, JavaScript
Backend Python 3.9+ with Pillow
Deployment Vercel Serverless Functions
Design Dark glassmorphism, Inter + JetBrains Mono fonts

📁 Project Structure

tds-image-compressor/
├── api/
│   └── compress.py      # Vercel serverless function (production API)
├── index.html            # Main application page
├── style.css             # Dark glassmorphism theme
├── app.js                # Frontend logic with retry & timeout
├── server.py             # Local development server
├── vercel.json           # Vercel deployment config
├── requirements.txt      # Python dependencies (Pillow)
├── .gitignore
├── LICENSE
└── README.md

🏃 Quick Start

Local Development

# Clone the repo
git clone https://github.com/GyaanFlow/tds-image-compressor.git
cd tds-image-compressor

# Install Pillow
pip install Pillow

# Start local server
python server.py

# Open http://localhost:8000

Deploy to Vercel

Option 1 — One-Click Deploy:

Deploy with Vercel

Option 2 — CLI:

npm install -g vercel
vercel login
vercel --prod

🔧 API Reference

POST /api/compress

Compress an image to lossless WebP.

Request:

curl -X POST -F "file=@image.png" https://your-app.vercel.app/api/compress

Response:

{
  "success": true,
  "compressed_image": "<base64-webp>",
  "original": { "size": 7082, "width": 500, "height": 500, "format": "PNG" },
  "compressed": { "size": 224, "width": 500, "height": 500, "format": "WebP" },
  "validation": {
    "size_under_limit": true,
    "dimensions_match": true,
    "is_lossless": true
  },
  "compression_ratio_percent": 96.84,
  "download_filename": "image.webp",
  "processing_ms": 30.7
}

GET /api/compress

Health check endpoint.

{ "status": "ok", "service": "image-compressor", "version": "2.0.0" }

🔒 How Lossless Verification Works

Original PNG → Decode to RGBA pixels → SHA-256 hash (A)
                    ↓
         Compress to WebP (lossless=True)
                    ↓
 WebP output → Decode to RGBA pixels → SHA-256 hash (B)
                    ↓
              Hash A == Hash B? → ✅ Pixel-identical!

Every compression is verified by comparing SHA-256 hashes of the raw pixel data before and after. If even one pixel differs, the verification fails.


🏗️ Production Features

  • Stateless serverless design — scales to lakhs of concurrent users
  • Decompression bomb protection — rejects images > 16M pixels
  • Memory cleanup — explicit GC-friendly cleanup for serverless
  • Security headersX-Content-Type-Options, X-Frame-Options, Referrer-Policy
  • Request timeout — 15s client-side timeout with auto-retry
  • Compact JSON — minimized response payloads for faster transfer

👤 Author

Gaurav Tomar — Python Developer

GitHub LinkedIn


📄 License

This project is licensed under the MIT License.


Built with 🐍 Python & deployed on ▲ Vercel
© 2025 Gaurav Tomar

Releases

Packages

Contributors

Languages