Say Goodbye to AI-Generated Pixel Art Headaches: The Complete Guide to unfake.js

Tired of inconsistent pixels and color bleeds in your AI-generated artwork? Discover how this open-source toolkit automatically cleans up pixel art and converts images to scalable vector graphics.

Creating pixel art or processing AI-generated images often comes with frustrating challenges:

  • Jagged edges from inconsistent pixel sizes
  • Color bleeds creating messy visuals
  • Blurry results after scaling
  • Manual pixel-by-pixel corrections

Meet 「unfake.js」 – an intelligent OpenCV.js-based solution that automatically cleans AI-generated pixel art and transforms raster images into infinitely scalable vector graphics. This comprehensive guide explores how this powerful toolkit solves real-world creative problems.

1. Core Functionality: Dual Processing Modes

1.1 Pixel Art Processor: Perfecting AI-Generated Artwork

This mode specifically addresses common artifacts in AI-generated pixel art through a multi-stage process:

  • 「Intelligent Scale Detection」: Automatically identifies the “true” pixel size of upscaled images using either:

    • runs-based algorithm (analyzing pixel patterns)
    • edge-aware method (detecting visual boundaries)
    • Manual scale factor override
  • 「Content-Aware Downscaling」: Reduces images to native 1x scale using advanced methods:

    • dominant (most frequent color selection)
    • median (statistical color median)
    • content-adaptive (context-sensitive reduction)
  • 「Grid Alignment」: Automatically crops images to align perfectly with detected pixel grids

  • 「Color Quantization」: Reduces color palettes using the high-quality image-q library with options for:

    • Maximum color limits (e.g., 32 colors)
    • Custom palette locking
    • Transparency preservation
  • 「Artifact Removal」: Post-processing options include:

    • Morphological cleanup (filling holes/removing noise)
    • Jaggy correction (smoothing stair-stepped edges)
    • Alpha binarization (sharp transparency handling)

1.2 Image Vectorizer: From Pixels to Scalable Vectors

Transform raster images (PNG/JPG) into clean SVG files with enhanced preprocessing:

  • 「Noise Reduction」: Pre-tracing filters:

    • Bilateral blur (edge-preserving smoothing)
    • Median blur (impulse noise reduction)
  • 「Smart Color Reduction」: Palette simplification before tracing with:

    • Automatic optimal color detection
    • Manual color count specification
  • 「Transparency Handling」: Special processing for transparent images:

    • Temporary background addition during processing
    • Automatic background removal in final SVG
  • 「Edge Refinement」: Post-quantization blurring for smoother outlines

  • 「Precision Tracing」: Customizable imagetracer.js parameters:

    • Path optimization (ltres/qtres)
    • Node simplification settings
    • Stroke detection thresholds

2. Browser-Based Tool: Zero-Code Solution

Pixel Art Processing Demo
Before/after comparison showing pixel grid alignment and color cleanup

Vectorization Demo
Raster-to-vector conversion with optimized color reduction

The included browser tool (/browser-tool) provides full functionality without programming:

Feature Overview

「Category」 「Features」 「User Benefit」
「Workflow」 Pixel Art/Vectorization mode toggle Single tool for multiple tasks
「Input」 Drag-drop, file selection, clipboard paste Flexible image importing
「Visualization」 Side-by-side comparison with magnifier Pixel-level quality inspection
「Control」 Real-time parameter adjustment via Tweakpane Instant visual feedback
「Color」 Interactive palette editor with color replacement Creative color customization
「Output」 PNG/SVG download & clipboard copy Seamless integration with design workflows

3. Practical Implementation Guide

3.1 Local Browser Tool Setup

「⚠️ Critical Requirement」: Modern browsers block ES module imports from local files. You MUST use a local server.

Quick Server Setup Options:

「Python 3.x Method:」

# Execute in project root directory
python -m http.server 8080
# Access at: http://localhost:8080/browser-tool/

「Node.js Method:」

# Install once: npm install -g http-server
http-server -p 8080
# Access at: http://localhost:8080/browser-tool/

「VS Code Method:」

  1. Install “Live Server” extension
  2. Right-click browser-tool/index.html
  3. Select “Open with Live Server”

3.2 Library Integration

Embed unfake.js functionality directly in your JavaScript projects:

Pixel Processing Implementation

import unfake from './lib/index.js';

// Configuration example
const options = {
    file: inputFile,          // Required image file
    maxColors: 32,            // Palette size limit
    detectMethod: 'auto',     // Scale detection mode
    downscaleMethod: 'median',// Reduction algorithm
    snapGrid: true,           // Enable grid alignment
    cleanup: { 
        morph: true,          // Enable morphological cleanup
        jaggy: true           // Enable jaggy correction
    }
};

// Processing execution
const { png, palette } = await unfake.processImage(options);

// Use result (PNG as Uint8Array)
const imgBlob = new Blob([png], { type: 'image/png' });
const imgUrl = URL.createObjectURL(imgBlob);

Vectorization Implementation

import unfake from './lib/index.js';

// Configuration example
const options = {
    file: inputFile,          // Required image file
    preProcess: {
        enabled: true,        // Enable noise reduction
        filter: 'bilateral', // Filter type selection
        value: 15            // Filter intensity
    },
    quantize: {
        enabled: true,        // Enable color reduction
        maxColors: 'auto'    // Automatic color detection
    },
    ltres: 1.1,               // Path optimization threshold
    qtres: 1.0                // Node simplification setting
};

// Vectorization execution
const { svg, palette } = await unfake.vectorizeImage(options);

// Use result (SVG as XML string)
document.getElementById('vector-container').innerHTML = svg;

4. Extended Ecosystem & Applications

4.1 Platform Integrations

4.2 Practical Use Cases

  1. 「Game Development」: Clean up AI-generated sprite sheets and textures
  2. 「Graphic Design」: Convert logos and icons to resolution-independent vectors
  3. 「Generative Art」: Refine outputs from AI art platforms like MidJourney
  4. 「Web Optimization」: Create crisp low-color assets for faster loading
  5. 「Print Production」: Ensure sharp results at any scale for physical products

5. Technical Foundation

Core Dependencies

「Library」 「Function」 「Key Contribution」
「OpenCV.js」 Computer vision operations Advanced image preprocessing
「ImageTracer.js」 Vectorization engine SVG path generation
「image-q」 Color quantization Optimal palette reduction
「UPNG.js」 PNG encoding/decoding Efficient image compression
「Tweakpane」 Parameter interface Interactive control panel

Processing Workflow

graph LR
A[Input Image] --> B(Preprocessing)
B --> C{Processing Mode}
C --> D[Pixel Art Mode]
C --> E[Vectorization Mode]
D --> F[Scale Detection]
D --> G[Grid Alignment]
D --> H[Color Quantization]
E --> I[Noise Reduction]
E --> J[Pre-Vector Quantization]
E --> K[Tracing]
F --> L[Downscaling]
G --> L
H --> L
L --> M[Artifact Removal]
I --> N[Post-Quantization Smoothing]
J --> K
K --> N
M --> O[Output PNG]
N --> P[Output SVG]

6. Frequently Asked Questions

「Q: How long does processing typically take?」
A: For 1000x1000px images: 2-5 seconds in browser, sub-second in Python port

「Q: Can I process transparent PNG files?」
A: Yes – alpha channels are preserved with special handling for clean edges

「Q: What’s the maximum image size supported?」
A: Browser tool: ~4000x4000px (varies by device); Python port: no hard limit

「Q: Which browsers support the web tool?」
A: Modern Chromium-based browsers (Chrome, Edge) and Firefox

「Q: Why do I need a local server for the browser tool?」
A: Browser security restrictions prevent direct file system access to ES modules

「Q: How does automatic color detection work?」
A: The algorithm analyzes color distribution to determine optimal palette size

「Q: Can I use this commercially?」
A: Yes – MIT license permits commercial use with attribution

7. Why Choose unfake.js?

After extensive testing, these advantages stand out:

  1. 「Automated Intelligence」: Complex image analysis requiring manual work elsewhere
  2. 「Dual-Mode Efficiency」: Single solution for pixel cleanup and vector conversion
  3. 「Open Accessibility」: MIT license enables free commercial/academic use
  4. 「Cross-Platform Support」: Browser, ComfyUI, and Python implementations
  5. 「Real-Time Control」: Interactive parameter tuning with instant feedback

“unfake.js bridges the critical gap between AI-generated content and production-ready assets”

8. Getting Started Recommendations

  1. 「First-Time Users」: Experiment with the itch.io online version
  2. 「Regular Users」: Clone repository for local browser tool access
  3. 「Developers」: Integrate library via NPM or direct ES module import
  4. 「Python Users」: Utilize the accelerated unfake.py port

「Pro Tip」: Start with default settings, then incrementally adjust one parameter at a time while observing results in the comparison view.

Conclusion

unfake.js addresses fundamental challenges in working with AI-generated images through:

  • Automated pixel grid detection and alignment
  • Intelligent color handling and quantization
  • Production-ready vectorization pipeline
  • Accessible browser interface
  • Developer-friendly API

The toolkit’s open-source nature and continuous development (with Python performance enhancements) make it an essential resource for digital creators working with AI-generated content.

「GitHub Repository」:
http://github.com/jenissimo/unfake.js

「Next Steps」:

  1. Experiment with sample images using the online demo
  2. Integrate into your workflow via preferred method (browser, API, or Python)
  3. Contribute to development via GitHub issues and pull requests

Transform your AI-generated artwork from problematic prototypes to production-ready assets with unfake.js today.