Skip to content

FatihAvdan/imgcrush

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚠️ UYARI: AI İLE ÜRETİLDİ

NOT: Bu proje tamamen AI (Yapay Zeka) kullanılarak, kendi kişisel kullanımım ve fotoğraf arşivimi hızlıca optimize etmek için üretilmiştir.


📸 imgcrush

Squoosh-quality image compressor CLI — Bulk resize & compress images to a target file size using Sharp (mozjpeg, libvips).

Compress hundreds of images to under 100KB (or any target) in seconds, while preserving the highest possible quality via binary-search optimization.


✨ Features

  • 🎯 Target file size — Set max KB per image (default: 100KB)
  • 🔍 Binary search quality — Finds the highest quality that fits your target size
  • 🚀 Blazing fast — Parallel processing with configurable concurrency
  • 📁 Recursive mode — Process nested folder structures
  • 🖼️ Multi-format — Supports JPG, PNG, WebP, AVIF, TIFF
  • 🔄 Format conversion — Force output to any supported format
  • 🧠 Smart skip — Automatically skips files already under target size
  • 📊 Detailed reporting — Colored CLI output with compression stats
  • 🏃 Dry run — Preview what would happen without writing files

📦 Installation

# Clone and install
git clone https://github.com/YOUR_USERNAME/imgcrush.git
cd imgcrush
npm install

# Or install globally
npm install -g .

🚀 Usage

Basic Usage

# Compress all images in ./photos to ./output (max 100KB each)
node compress.js ./photos ./output

# If installed globally
imgcrush ./photos ./output

Options

Flag Description Default
-s, --max-size <KB> Maximum file size in KB 100
-c, --concurrency <N> Number of parallel processes 4
-r, --recursive Process subfolders recursively false
-f, --format <fmt> Force output format: jpg, png, webp, avif auto
-q, --min-quality <N> Minimum quality threshold (1-100) 10
--skip-existing Skip files that already exist in output false
--dry-run Preview without writing any files false
-v, --version Show version
-h, --help Show help message

Examples

# Compress to max 50KB per image
imgcrush ./photos ./compressed -s 50

# Convert everything to WebP
imgcrush ./photos ./webp-output -f webp

# Process recursively with 8 parallel threads
imgcrush ./photos ./output -r -c 8

# Dry run to see what would be processed
imgcrush ./photos ./output --dry-run

# Resume a previous run (skip already processed files)
imgcrush ./photos ./output --skip-existing

# Compress with minimum quality of 30 (higher quality floor)
imgcrush ./photos ./output -q 30 -s 200

🔧 How It Works

  1. Scan — Collects all supported image files from the input directory
  2. Skip — Files already under the target size are copied as-is
  3. Estimate — Calculates an initial resize ratio based on file size
  4. Binary Search — Iteratively finds the optimal quality setting:
    • Tests the lowest quality first
    • If still too large, reduces dimensions progressively
    • Binary searches between min and max quality to find the highest quality that fits
  5. Write — Saves the optimized image with the same filename to the output directory

Compression Pipeline

Input Image → Resize (if needed) → Format Encode (mozjpeg) → Binary Search Quality → Output
  • JPEG/JPG: Uses mozjpeg encoder for superior compression
  • PNG: Preserved as PNG by default, or converted to JPEG with --format jpg
  • WebP/AVIF: Supported as both input and output formats

📊 Sample Output

  ╔══════════════════════════════════════════════════════════╗
  ║           📸  imgcrush v1.0.0                          ║
  ║         Squoosh-quality image compression                ║
  ╚══════════════════════════════════════════════════════════╝

  📂 Input:        C:\photos
  📂 Output:       C:\compressed
  📊 Dosya sayısı: 244 fotoğraf (203.9 MB)
  🎯 Hedef:        Her dosya max 100 KB
  📦 Format:       otomatik (JPG)
  ⚡ Paralel:      4 işlem

  [  1/244] 🔧 photo1.jpg — 1.1 MB → 98.5 KB (-%91.2 | Q:65 | 3024x4032 → 1024x1365)
  [  2/244] ✅ photo2.jpg — 45.2 KB (hedef altında)
  ...

  ╔══════════════════════════════════════════════════════════╗
  ║                      📊 SONUÇLAR                        ║
  ╚══════════════════════════════════════════════════════════╝
  📁 Toplam dosya:        244
  🔧 Sıkıştırılan:       226
  ⏭️  Atlanan (<100KB):    18
  📦 Önce:               203.9 MB
  📦 Sonra:              23.0 MB
  💾 Tasarruf:           180.9 MB (-%88.7)
  ⏱️  Süre:              69.5 saniye

🛠️ Requirements

  • Node.js >= 16.0.0
  • sharp (automatically installed via npm)

📜 License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors