Skip to content

Arghajit47/Visual-image-comparer

Repository files navigation

🎨 Visual Image Comparer

A powerful pixel-by-pixel image comparison tool with advanced visual diff overlay

Next.js TypeScript ResembleJS License

Live Demo β€’ Features β€’ Quick Start β€’ API Config β€’ Deployment


πŸ“– Overview

Visual Image Comparer is a sophisticated web application that enables precise visual comparison between two images. Built with Next.js and powered by ResembleJS, it provides pixel-level analysis with an interactive diff overlay, similarity percentage calculations, and comprehensive configuration options for various comparison scenarios.

🎯 Perfect For

  • UI/UX Testing: Detect visual regressions in web/mobile interfaces
  • A/B Testing: Compare design variations side-by-side
  • Screenshot Comparison: Validate rendering across browsers/devices
  • Quality Assurance: Automated visual testing in CI/CD pipelines
  • Design Review: Highlight subtle differences between design iterations
  • Game Development: Compare textures, sprites, and rendered frames

✨ Features

πŸ” Core Capabilities

  • Pixel-Perfect Analysis: Compare images down to individual pixel differences
  • Visual Diff Overlay: Interactive color-coded difference highlighting
  • Similarity Percentage: Precise mismatch calculation (0-100%)
  • Dual Input Methods: Upload files OR paste image URLs
  • Real-time Preview: See base, actual, and diff images side-by-side
  • Threshold Control: Set acceptable difference tolerance (0-100%)
  • Pass/Fail Status: Automatic comparison verdict based on threshold

βš™οΈ Advanced Configuration

Output Settings

  • Error Color Customization: RGB color picker for diff highlighting
  • Error Type: Choose between flat, movement, or flatDifferenceIntensity
  • Transparency: Adjust diff overlay opacity (0.0 - 1.0)
  • Large Image Threshold: Optimize performance for large images
  • Cross-Origin Support: Handle CORS-protected images

Comparison Options

  • Scale to Same Size: Auto-resize images before comparison
  • Ignore Anti-aliasing: Skip anti-aliasing pixel differences
  • Ignore Colors: Compare structure only (grayscale)
  • Ignore Alpha Channel: Exclude transparency from comparison
  • Early Return Threshold: Stop analysis when threshold exceeded (performance boost)

🎨 User Experience

  • Responsive Design: Works seamlessly on desktop, tablet, and mobile
  • Dark/Light Mode: (Coming soon)
  • Drag & Drop: Upload images effortlessly
  • Image Download: Export diff results as PNG
  • Reset Functionality: Clear all inputs and start fresh
  • Tooltips & Help: User-friendly explanations for all options
  • Loading States: Visual feedback during processing
  • Error Handling: Graceful fallbacks with helpful error messages

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Full Stack (Netlify)                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Frontend - Next.js 15.5 + React 18 + TypeScript     β”‚  β”‚
β”‚  β”‚  β”œβ”€β”€ Client-side ResembleJS (Browser)                β”‚  β”‚
β”‚  β”‚  β”œβ”€β”€ Shadcn/ui Components                            β”‚  β”‚
β”‚  β”‚  β”œβ”€β”€ Tailwind CSS                                    β”‚  β”‚
β”‚  β”‚  └── Image Upload & URL Input                        β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                          ↕ HTTPS                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Serverless API Routes (Netlify Functions)           β”‚  β”‚
β”‚  β”‚  β”œβ”€β”€ /api/health - Health check endpoint            β”‚  β”‚
β”‚  β”‚  β”œβ”€β”€ /api/compare-images - Image comparison         β”‚  β”‚
β”‚  β”‚  β”œβ”€β”€ Sharp (image processing)                        β”‚  β”‚
β”‚  β”‚  β”œβ”€β”€ Pixelmatch (comparison algorithm)              β”‚  β”‚
β”‚  β”‚  └── CORS-enabled responses                          β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”§ Technology Stack

Layer Technology Purpose
Frontend Next.js 15.5 React framework with App Router
UI Library Shadcn/ui Accessible component system
Styling Tailwind CSS Utility-first CSS framework
Image Analysis ResembleJS 5.0 Client-side pixel comparison
API Next.js Routes Serverless API endpoints
Image Processing Sharp Server-side image manipulation
Comparison Pixelmatch Server-side pixel comparison
Type Safety TypeScript 5.0 Static type checking
Deployment Netlify CDN + Serverless Functions

πŸš€ Quick Start

πŸ“š New to the project? Check out DEPLOYMENT.md for production deployment guide!

Prerequisites

Node.js >= 18.0.0
npm >= 9.0.0 or yarn >= 1.22.0

Installation

# Clone the repository
git clone https://github.com/Arghajit47/visual-image-comparer.git
cd visual-image-comparer

# Install dependencies
npm install

# Create environment file
cp .env.example .env.local

# Start development server
npm run dev

Open http://localhost:3000 in your browser.

Environment Variables

Create .env.local in the root directory:

# API Configuration
NEXT_PUBLIC_API_URL=http://localhost:3000

# CORS Configuration (optional)
ALLOWED_ORIGIN=*

# Node Environment
NODE_ENV=development

πŸ’» Usage

1️⃣ Basic Comparison

// Upload two images or provide URLs
// Click "Compare Images"
// View results: similarity percentage + diff overlay

2️⃣ Advanced Configuration

// Expand "Advanced Options" accordion
// Customize error color (default: magenta RGB(255, 0, 255))
// Adjust transparency (default: 0.3)
// Set comparison threshold (default: 0%)

3️⃣ API Integration

πŸŽ›οΈ Full API Documentation: See API_CONFIG.md for all configuration options!

POST /api/compare-images
Content-Type: application/json

{
  "baseImageSource": "data:image/png;base64,...",
  "actualImageSource": "https://example.com/image.png",
  "threshold": 5,
  "options": {
    "pixelmatch": {
      "threshold": 0.1,
      "diffColor": [255, 0, 255]
    },
    "resize": {
      "enabled": true,
      "strategy": "fill"
    },
    "output": {
      "format": "png",
      "includeMetadata": true
    }
  }
}

Response:

{
  "differencePercentage": 2.45,
  "status": "Passed",
  "diffImageUrl": "data:image/png;base64,...",
  "metadata": {
    "baseImage": { "width": 1920, "height": 1080 },
    "comparison": { "totalPixels": 2073600, "diffPixels": 50803 }
  },
  "error": null
}

🌐 Deployment

πŸ“– Complete Guide: See DEPLOYMENT.md for detailed instructions!

Deploy to Netlify

Frontend + Serverless API in one deployment!

# 1. Push to GitHub
git push origin main

# 2. Connect to Netlify
# Dashboard β†’ New site β†’ Import from Git

# 3. Auto-configured via netlify.toml
# Build: npm run build
# Publish: .next
# Functions: Automatic (Next.js API routes)

# 4. Deploy! βœ…

Features:

  • βœ… Zero-config serverless functions
  • βœ… Automatic HTTPS
  • βœ… Preview deployments for PRs
  • βœ… 100GB bandwidth/month (free)
  • βœ… Support for all image formats (PNG, JPEG, WebP, GIF, SVG, AVIF, TIFF)

πŸ“‚ Project Structure

visual-image-comparer/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   β”œβ”€β”€ compare-images/
β”‚   β”‚   β”‚   β”‚   └── route.ts          # Image comparison endpoint
β”‚   β”‚   β”‚   └── health/
β”‚   β”‚   β”‚       └── route.ts          # Health check endpoint
β”‚   β”‚   β”œβ”€β”€ globals.css               # Global styles
β”‚   β”‚   β”œβ”€β”€ layout.tsx                # Root layout
β”‚   β”‚   └── page.tsx                  # Home page
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ ui/                       # Shadcn/ui components
β”‚   β”‚   β”œβ”€β”€ ImageComparer.tsx         # Main comparison component
β”‚   β”‚   └── ImageComparerLoader.tsx   # Client-side loader
β”‚   β”œβ”€β”€ hooks/                        # Custom React hooks
β”‚   └── lib/
β”‚       └── utils.ts                  # Utility functions
β”œβ”€β”€ .env.example                      # Environment template
β”œβ”€β”€ .env.local                        # Local environment (git-ignored)
β”œβ”€β”€ netlify.toml                      # Netlify config (serverless)
β”œβ”€β”€ package.json                      # Dependencies
β”œβ”€β”€ tsconfig.json                     # TypeScript config
β”œβ”€β”€ API_CONFIG.md                     # πŸŽ›οΈ API configuration guide
β”œβ”€β”€ DEPLOYMENT.md                     # πŸš€ Deployment instructions
└── README.md                         # You are here!

πŸ”§ Configuration Options

πŸ“– Full Documentation: See API_CONFIG.md for comprehensive configuration guide!

Quick Reference

Category Options Description
Pixelmatch threshold, diffColor, includeAA Comparison algorithm settings
Resize enabled, strategy, width, height Auto-resize configuration
Output format, includeMetadata, includeDiffBounds Response customization
Quality png, jpeg, webp Output image quality
Performance maxDimension, timeout, earlyExit Performance tuning

Example:

{
  "options": {
    "pixelmatch": { "threshold": 0.1, "diffColor": [255, 0, 255] },
    "resize": { "enabled": true, "strategy": "fill" },
    "output": { "format": "png", "includeMetadata": true }
  }
}

πŸ§ͺ Testing

# Type checking
npm run typecheck

# Linting
npm run lint

# Test health endpoint
curl http://localhost:3000/api/health

πŸ› Troubleshooting

CORS Errors

Issue: Access-Control-Allow-Origin blocked

Solution:

  1. Set ALLOWED_ORIGIN environment variable in Netlify
  2. Ensure https:// protocol is included
  3. Remove trailing slashes from URLs
  4. Check API routes return proper CORS headers

Large Image Performance

Issue: Slow comparison or browser freeze

Solution:

  1. Enable "Scale to Same Size" option
  2. Increase "Large Image Threshold" value
  3. Set "Return Early Threshold" to stop at acceptable mismatch
  4. Use server-side API for very large images

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

πŸ“š Documentation


πŸ“„ License

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


πŸ™ Acknowledgments


πŸ“ž Support


πŸ—ΊοΈ Roadmap

  • Dark mode support
  • Batch comparison (multiple image pairs)
  • Comparison history/session management
  • Export comparison reports (PDF/JSON)
  • API rate limiting and authentication
  • Image preprocessing (crop, rotate, filters)
  • Integration with CI/CD platforms
  • WebSocket for real-time comparison status
  • Advanced diff algorithms (SSIM, MSE, PSNR)
  • Browser extension for quick comparisons

Made by Arghajit Singha

⭐ Star this repo if you find it helpful!

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages