Skip to content

Free and Open Source Image Compressor. Optimizes images locally, delivering unmatched efficiency without storing a single file. Experience lightning-fast compression, all in one place

License

Notifications You must be signed in to change notification settings

abue-ammar/image-compressor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Overview

Free and Open Source Image Compressor. Optimizes images locally, delivering unmatched efficiency without storing a single file. Experience lightning-fast compression, all in one place.

Live

https://image-compressor.github.io

Architecture & Code Structure

This project uses a modern, modular architecture with clear separation of concerns. The codebase is organized into focused components, custom hooks, and utility functions for optimal maintainability and testability.

Project Structure

β”œβ”€β”€ public/                     # Static assets and PWA manifest
β”‚   β”œβ”€β”€ logo.png               # Application logo variants
β”‚   β”œβ”€β”€ logo.svg               # SVG logo files
β”‚   β”œβ”€β”€ manifest.json          # PWA manifest configuration
β”‚   └── fonts/                 # Custom font files
β”œβ”€β”€ src/                       # Frontend source code (React + TypeScript)
β”‚   β”œβ”€β”€ components/            # React components
β”‚   β”‚   β”œβ”€β”€ ui/               # Reusable UI components (shadcn/ui)
β”‚   β”‚   β”œβ”€β”€ action-buttons.tsx         # Download/Reset functionality
β”‚   β”‚   β”œβ”€β”€ compressed-images-grid.tsx # Grid display for results
β”‚   β”‚   β”œβ”€β”€ drop-zone.tsx              # File upload interface
β”‚   β”‚   β”œβ”€β”€ image-preview-card.tsx     # Individual image preview
β”‚   β”‚   β”œβ”€β”€ image-quality-slider.tsx   # Compression quality control
β”‚   β”‚   β”œβ”€β”€ loading-spinner.tsx        # Loading states
β”‚   β”‚   β”œβ”€β”€ theme-provider.tsx         # Dark/light theme support
β”‚   β”‚   └── [other components]
β”‚   β”œβ”€β”€ hooks/                 # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ useDragAndDrop.ts         # Drag & drop functionality
β”‚   β”‚   └── useImageCompression.ts    # Core compression logic
β”‚   β”œβ”€β”€ lib/                   # Utility libraries
β”‚   β”‚   └── utils.ts                  # Common utility functions
β”‚   β”œβ”€β”€ types/                 # TypeScript type definitions
β”‚   β”‚   └── image-compressor.ts       # Core type interfaces
β”‚   β”œβ”€β”€ utils/                 # Utility functions
β”‚   β”‚   β”œβ”€β”€ download.ts              # File download utilities
β”‚   β”‚   β”œβ”€β”€ file-validation.ts       # File type validation
β”‚   β”‚   β”œβ”€β”€ image-compression.ts     # Image processing logic
β”‚   β”‚   └── utils.ts                 # General utilities
β”‚   β”œβ”€β”€ App.tsx               # Main application component
β”‚   β”œβ”€β”€ main.tsx              # Application entry point
β”‚   └── index.css             # Global styles
β”œβ”€β”€ src-tauri/                 # Tauri backend (Rust)
β”‚   β”œβ”€β”€ src/                  # Rust source code
β”‚   β”‚   β”œβ”€β”€ lib.rs           # Library functions
β”‚   β”‚   └── main.rs          # Application entry
β”‚   β”œβ”€β”€ icons/               # Application icons for platforms
β”‚   β”œβ”€β”€ capabilities/        # Tauri security capabilities
β”‚   β”œβ”€β”€ gen/                 # Generated build files
β”‚   β”‚   └── android/         # Android-specific build files
β”‚   β”œβ”€β”€ Cargo.toml          # Rust dependencies
β”‚   β”œβ”€β”€ tauri.conf.json     # Tauri configuration
β”‚   └── build.rs            # Build script
β”œβ”€β”€ package.json             # Node.js dependencies and scripts
β”œβ”€β”€ tsconfig.json           # TypeScript configuration
β”œβ”€β”€ vite.config.ts          # Vite build configuration
β”œβ”€β”€ eslint.config.js        # ESLint linting rules
└── components.json         # shadcn/ui components configuration

Core Components

ImageCompressor (Main Component)

  • Purpose: Main container that orchestrates the entire compression workflow
  • Size: Optimized from ~410 lines to ~70 lines through modular design
  • Responsibilities: Layout management, scroll behavior, component coordination

DropZone

  • Purpose: Handles file upload via drag & drop or file input
  • Features: Visual drag feedback, file validation, multi-file support
  • Integration: Works with useDragAndDrop hook and file validation utilities

ActionButtons

  • Purpose: Provides download and reset functionality
  • Features: ZIP download, individual image download, state reset
  • Platform Support: Tauri-compatible download handling

CompressedImagesGrid

  • Purpose: Displays compressed images in a responsive grid
  • Features: Empty state handling, individual image actions, responsive layout

Custom Hooks

useImageCompression

  • Purpose: Core compression logic and state management
  • State: Compressed images, ZIP files, loading states, progress tracking
  • Methods: handleImageUpload, onImageQualityChange, resetCompression

useDragAndDrop

  • Purpose: Drag and drop functionality management
  • Features: Drag state tracking, event handling, file validation integration

Utility Functions

file-validation.ts

  • Exports: ALLOWED_FORMATS, validateFileType, filterValidFiles
  • Purpose: Comprehensive file type validation and error handling

image-compression.ts

  • Exports: compressImage, processImages
  • Purpose: Core image processing with progress tracking

download.ts

  • Exports: downloadZip, downloadSingleImage
  • Purpose: Cross-platform file download (Tauri & web compatible)

TypeScript Integration

image-compressor.ts

  • Exports: CompressedImage, ImageCompressorState
  • Purpose: Type-safe interfaces for all components and utilities

Key Features

  • 🎯 Modular Architecture: Each component has a single responsibility
  • πŸ”§ Type Safety: Full TypeScript integration with strict typing
  • πŸ“± Cross-Platform: Tauri-based desktop app with web fallback
  • 🎨 Modern UI: shadcn/ui components with dark/light theme support
  • ⚑ Performance: Optimized compression with progress tracking
  • πŸ§ͺ Testable: Isolated components and utilities for easy testing
  • πŸ”„ Reusable: Components can be used across different parts of the app

Usage Examples

// Import individual components
import { ImageCompressor, DropZone, ActionButtons } from "./components";
import { useImageCompression, useDragAndDrop } from "./hooks";
import { validateFileType, downloadZip } from "./utils";

// Or import from main index
import {
  ImageCompressor,
  useImageCompression,
  CompressedImage,
} from "./image-compressor";

Getting Started

Prerequisites

  • Node.js version 20+ and npm installed on your machine
  • For Tauri development: Rust toolchain installed

Installation

# Clone the repository
git clone https://github.com/abue-ammar/image-compressor.git
cd image-compressor

# Install dependencies
npm install

# Start development server
npm start

Open your browser and go to http://localhost:3000 to use the image compressor.

Available Scripts

# Development
npm start          # Start development server
npm run dev        # Alternative development command

# Building
npm run build      # Build for production
npm run preview    # Preview production build

# Tauri (Desktop App)
npm run tauri dev  # Start Tauri development
npm run tauri build # Build desktop application

# Code Quality
npm run lint       # Run ESLint
npm run type-check # Run TypeScript compiler check

Development Workflow

  1. Frontend Development: Use npm start for hot-reload React development
  2. Desktop App Development: Use npm run tauri dev for Tauri development
  3. Testing: Run individual component tests with the modular structure
  4. Building: Use npm run build for web or npm run tauri build for desktop

Project Highlights

  • Zero Dependencies for Core Functionality: No external image processing libraries
  • Privacy First: All processing happens locally, no data leaves your device
  • Cross-Platform: Runs in browsers and as a desktop application
  • Modern Stack: React 18, TypeScript, Vite, Tauri, shadcn/ui
  • Optimized Performance: Efficient compression algorithms with progress tracking

Features

  • πŸ–ΌοΈ Multi-Format Support: JPEG, PNG, WebP, and more
  • 🎚️ Quality Control: Adjustable compression levels with live preview
  • πŸ“¦ Batch Processing: Compress multiple images simultaneously
  • πŸ’Ύ Flexible Downloads: Download individual images or ZIP archives
  • πŸ–±οΈ Drag & Drop: Intuitive file upload interface
  • πŸ“± Responsive Design: Works on desktop and mobile devices
  • πŸŒ™ Dark/Light Theme: Automatic theme switching support
  • πŸ”’ Privacy Focused: All processing happens locally in your browser
  • ⚑ Fast Performance: Optimized compression algorithms
  • πŸ–₯️ Desktop App: Available as a native desktop application via Tauri

Contributing

We welcome contributions! Here's how you can help:

Development Setup

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Install dependencies: npm install
  4. Start development: npm start
  5. Make your changes
  6. Test thoroughly
  7. Commit your changes: git commit -m 'Add amazing feature'
  8. Push to the branch: git push origin feature/amazing-feature
  9. Open a Pull Request

Code Style

  • Follow TypeScript best practices
  • Use the existing component structure
  • Maintain the modular architecture
  • Add proper type definitions
  • Write meaningful commit messages

Testing

  • Test components in isolation
  • Verify cross-platform compatibility (web + Tauri)
  • Test with various image formats and sizes
  • Ensure accessibility standards are met

Areas for Contribution

  • New image formats support
  • Performance optimizations
  • UI/UX improvements
  • Mobile responsiveness
  • Accessibility enhancements
  • Documentation improvements

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Free and Open Source Image Compressor. Optimizes images locally, delivering unmatched efficiency without storing a single file. Experience lightning-fast compression, all in one place

Topics

Resources

License

Stars

Watchers

Forks