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.
- π₯οΈ 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
Input: .jpg, .jpeg, .png, .webp, .bmp, .tiff
Output: webp, jpeg, png, original (optimized versions of input format)
- Node.js 18+
- npm or yarn
-
Clone the repository
git clone <repository-url> cd image-optimizer-electron
-
Install dependencies
npm install
Development Mode
npm run devProduction Mode
npm start# 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 --x64After building, you'll find the packaged applications in the dist/ directory:
- macOS:
Image Optimizer-1.0.0-arm64.dmgand.appbundle - Windows:
Image Optimizer Setup 1.0.0.exeand portable.exe - Linux:
Image Optimizer-1.0.0.AppImageand.debpackage
The build process creates several files:
.dmg/.exe/.AppImage- Installer packages.zip- Portable application archives.blockmap- Delta update fileslatest-*.yml- Auto-updater manifests
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
- Main Process (
main.js) - Manages the application lifecycle and creates browser windows - Renderer Process (
renderer/) - Handles the user interface and user interactions - Preload Script (
preload.js) - Provides secure communication bridge between main and renderer - Optimization Script (
scripts/optimize.js) - Performs actual image processing using Sharp
- Folder Selection: User selects a folder containing images via native dialog
- Format Selection: Choose output format (WebP, JPEG, PNG, or optimized original)
- Child Process: Main process spawns
optimize.jsas a child process with CLI arguments - Real-Time Streaming: Processing logs stream back to UI via IPC events
- Output: Optimized images are saved to
selectedFolder/optimized/
// 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)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- electron-builder - Build and packaging tool
- eslint - Code linting with Airbnb base config
- prettier - Code formatting
- eslint-config-airbnb-base - Airbnb ESLint rules
- 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
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
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
- Launch the application
- Click "Select Folder" and choose a directory with images
- Select your preferred output format (WebP recommended for best compression)
- Click "Optimize" and watch real-time progress
- Find optimized images in the
optimizedsubfolder
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 sharpBuild fails on macOS: Make sure Xcode command line tools are installed:
xcode-select --installWindows 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"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.
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.
Edit package.json build configuration to customize:
{
"build": {
"appId": "com.yourcompany.imageoptimizer",
"productName": "Your Image Optimizer",
"directories": { "output": "dist" },
"asarUnpack": ["node_modules/**/*", "scripts/**/*"]
}
}The build configuration is ready for auto-update integration. Consider using:
- electron-updater for desktop updates
- GitHub Releases or a custom update server
MIT License - feel free to use this project for personal or commercial purposes.
Built with β€οΈ using Electron and Sharp