Skip to content

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

16 Commits

Folders and files

Repository files navigation

Image Optimizer - Electron Desktop App

A lightweight desktop application built with Electron and Node.js for optimizing images using the powerful Sharp library. Select a folder, choose your desired output format, and watch as all images are optimized with real-time progress feedback.

Image Optimizer Demo Node.js Sharp

πŸš€ Features

  • πŸ–₯️ Native Desktop App: Built with Electron for cross-platform compatibility
  • ⚑ Fast Image Processing: Powered by Sharp for high-performance image optimization
  • πŸ“ Folder-Based Processing: Select any folder and optimize all images at once
  • πŸ”„ Real-Time Progress: Live streaming of optimization progress to the UI
  • 🎯 Multiple Formats: Support for WebP, JPEG, PNG, and original format optimization
  • πŸ”’ Secure Architecture: Uses Electron's contextBridge for secure IPC communication
  • πŸ“Š Detailed Feedback: Shows file sizes, compression ratios, and processing status
  • 🎨 Clean UI: Simple, responsive interface with no frameworks - just vanilla JS
  • πŸ“¦ Ready for Distribution: Fully packaged apps for macOS, Windows, and Linux

πŸ“‹ Supported Image Formats

Input: .jpg, .jpeg, .png, .webp, .bmp, .tiff
Output: webp, jpeg, png, original (optimized versions of input format)

πŸ› οΈ Setup

Prerequisites

  • Node.js 18+
  • npm or yarn

Installation

  1. Clone the repository

    git clone <repository-url>
    cd image-optimizer-electron
  2. Install dependencies

    npm install

🎯 Running the App

Development Mode

npm run dev

Production Mode

npm start

πŸ“¦ Building & Distribution

Build Commands

# Build for all platforms
npm run dist

# Build for specific platforms
npm run dist -- --mac
npm run dist -- --win  
npm run dist -- --linux

# Build for specific architecture
npm run dist -- --mac --arm64
npm run dist -- --win --x64

Build Output

After building, you'll find the packaged applications in the dist/ directory:

  • macOS: Image Optimizer-1.0.0-arm64.dmg and .app bundle
  • Windows: Image Optimizer Setup 1.0.0.exe and portable .exe
  • Linux: Image Optimizer-1.0.0.AppImage and .deb package

Distribution Files

The build process creates several files:

  • .dmg / .exe / .AppImage - Installer packages
  • .zip - Portable application archives
  • .blockmap - Delta update files
  • latest-*.yml - Auto-updater manifests

πŸ“ Project Structure

image-optimizer-electron/
β”œβ”€β”€ main.js                 # Main Electron process - window management & IPC
β”œβ”€β”€ preload.js              # Secure IPC bridge via contextBridge
β”œβ”€β”€ package.json            # Dependencies and scripts
β”œβ”€β”€ scripts/
β”‚   └── optimize.js         # Node.js script using Sharp for image processing
β”œβ”€β”€ renderer/
β”‚   β”œβ”€β”€ index.html          # UI structure
β”‚   └── app.js              # DOM logic & IPC communication
β”œβ”€β”€ assets/                 # App icons for different platforms
β”‚   β”œβ”€β”€ icon.icns          # macOS icon
β”‚   β”œβ”€β”€ icon.ico           # Windows icon
β”‚   └── icon.png           # Linux icon
β”œβ”€β”€ dist/                  # Build output (generated)
└── .cursor/
    └── rules/             # Development rules and architecture guidelines

βš™οΈ How It Works

Architecture Overview

  1. Main Process (main.js) - Manages the application lifecycle and creates browser windows
  2. Renderer Process (renderer/) - Handles the user interface and user interactions
  3. Preload Script (preload.js) - Provides secure communication bridge between main and renderer
  4. Optimization Script (scripts/optimize.js) - Performs actual image processing using Sharp

Processing Flow

  1. Folder Selection: User selects a folder containing images via native dialog
  2. Format Selection: Choose output format (WebP, JPEG, PNG, or optimized original)
  3. Child Process: Main process spawns optimize.js as a child process with CLI arguments
  4. Real-Time Streaming: Processing logs stream back to UI via IPC events
  5. Output: Optimized images are saved to selectedFolder/optimized/

IPC Communication

// Real-time log streaming
main β†’ renderer: 'optimize-log' (individual log messages)
main β†’ renderer: 'optimize-complete' (final status)

// User actions  
renderer β†’ main: 'select-folder' (folder selection)
renderer β†’ main: 'optimize-images' (start processing)

πŸ”§ Available Scripts

npm run dev          # Run in development mode
npm start            # Run in production mode
npm run build        # Build for distribution (all platforms)
npm run dist         # Build for distribution (all platforms)  
npm run lint         # Check code quality with ESLint
npm run lint:fix     # Auto-fix linting issues
npm run format       # Format code with Prettier
npm run format:check # Check code formatting

πŸ“¦ Dependencies

Production

  • electron - Desktop app framework
  • sharp - High-performance image processing

Development

🎨 UI Features

  • Clean Interface: Styled with Water.css for a modern, lightweight design
  • Real-Time Feedback: Progress updates appear instantly as each image is processed
  • Auto-Scrolling Output: Automatically scrolls to show the latest processing updates
  • Visual Status Indicators: Clear βœ…/❌ indicators for success and failure states
  • Responsive Design: Works well across different window sizes

πŸ”’ Security

This app follows Electron security best practices:

  • Context Isolation: Renderer processes run in isolated contexts
  • No Node.js Integration: Renderer cannot directly access Node.js APIs
  • Secure IPC: All communication goes through the secure contextBridge API
  • Minimal API Surface: Only necessary APIs are exposed to the renderer

πŸ—οΈ Development Guidelines

The project follows strict architectural principles:

  • Separation of Concerns: Clear boundaries between UI, logic, and system integration
  • Security First: All IPC communication uses contextBridge pattern
  • No Overengineering: Simple, maintainable code without unnecessary abstractions
  • Image Processing: All image transformations use Sharp library exclusively

πŸ“ Example Usage

  1. Launch the application
  2. Click "Select Folder" and choose a directory with images
  3. Select your preferred output format (WebP recommended for best compression)
  4. Click "Optimize" and watch real-time progress
  5. Find optimized images in the optimized subfolder

πŸ› Troubleshooting

Development Issues

App won't start: Ensure Node.js 18+ is installed and dependencies are installed with npm install

No images found: Make sure your folder contains supported image formats (jpg, png, webp, etc.)

Sharp installation issues: Sharp may need to rebuild for your platform:

npm rebuild sharp

Build Issues

Build fails on macOS: Make sure Xcode command line tools are installed:

xcode-select --install

Windows build fails: Install Visual Studio Build Tools or Visual Studio Community

Linux build fails: Install required build dependencies:

sudo apt-get install build-essential libnss3-dev libatk-bridge2.0-dev

Packaged App Issues

"Cannot find module" errors: This typically happens when native modules aren't properly unpacked. The current configuration unpacks all node_modules to resolve this.

Sharp not working in packaged app: All Sharp dependencies (including detect-libc) are now properly included via the asarUnpack configuration.

Script execution fails: The app uses fork() instead of spawn() for better Node.js script execution in packaged environments.

Performance Tips

Large image folders: The app processes images sequentially to avoid memory issues. For very large folders (1000+ images), consider processing in batches.

Memory usage: Sharp is memory-efficient, but very large images (>50MB) may require more system RAM.

πŸ”§ Advanced Configuration

Customizing Build Settings

Edit package.json build configuration to customize:

{
  "build": {
    "appId": "com.yourcompany.imageoptimizer",
    "productName": "Your Image Optimizer",
    "directories": { "output": "dist" },
    "asarUnpack": ["node_modules/**/*", "scripts/**/*"]
  }
}

Adding Auto-Updates

The build configuration is ready for auto-update integration. Consider using:

  • electron-updater for desktop updates
  • GitHub Releases or a custom update server

πŸ“„ License

MIT License - feel free to use this project for personal or commercial purposes.


Built with ❀️ using Electron and Sharp

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages