unfake.js

jenissimoMIT活跃维护

在浏览器里直接修复 AI 生成的像素画和矢量图,不用装软件或上传服务器,适合处理文生图常见的锯齿、模糊和边缘失真问题。

Fix AI pixel art and vector images right in your browser

v1.4.0发布于 2026-09-29 15:15 UTC940star63fork同步于 2026-11-07 07:30 UTC

怎么上手

由 README 提炼,执行前请确认
python -m http.server 8080
# 打开 http://localhost:8080/browser-tool/
硬件要求按 README 说明

README 未说明;核心为 Rust 编译的 WebAssembly,在浏览器中运行,未提及 GPU 或显存要求

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

在浏览器里修复 AI 生成的像素画和矢量图,输出干净可用的素材

在浏览器里直接修复 AI 生成的像素画和矢量图,不用装软件或上传服务器,适合处理文生图常见的锯齿、模糊和边缘失真问题。

核心能力

  • 自动检测放大像素画的真实像素尺寸,支持分数网格
  • 用 dominant、median 等算法降采样回原生 1x 且不引入新色
  • 用 imagequant 做颜色量化并支持固定自定义调色板
  • 形态学与锯齿清理、alpha 二值化去除杂边
  • 矢量化前降噪量化、后平滑,输出干净 SVG

容易踩的坑

浏览器工具必须通过本地 http(s) 服务器打开,file:// 无法加载 ES 模块;自行集成时需先构建 WASM 核心(bun run core:wasm)到 browser-tool/vendor/unfake-core/;矢量化依赖 ImageTracer.js,需一并引入

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

3 个版本v1.4.0
  1. v1.4.0v1.4.0 — Fractional and elastic pixel grids最新正式版2026-09-29 · 2026-09-29 15:15 UTC

    Scale detection now follows grids that aren't a whole number of pixels, and grids that were drawn by hand.

    Newer image models draw pixel art on an N×N canvas and resample it to the output size: 200 cells at 2048 px is 10.24 px per cell, at 500 px it is 2.5. Until now unfake rounded that to 10, so the grid drifted a whole cell every few cells and rows and columns came out doubled, or it doubled 2.5 to 5 and lost half the resolution. Other models draw the "pixels" by hand and their size wanders (columns of 40 to 49 px around a 43 px scale), so any fixed grid ends up half a cell off somewhere and a pixel gets doubled or dropped there.

    Highlights

    • Fractional grids. Cell size and phase are measured per axis from the image itself (e.g. 10.24 × 10.24 px → exactly 200 × 200 cells), and cells are sampled in place, without a snap crop.
    • Elastic grid. When the drawn cells jitter around the scale, cell boundaries are fitted to the actual edges on that axis. It only kicks in where it lines up clearly better with the edges than a fixed grid does, for cells of 8 px and up. Toggle: Elastic Grid (on by default).
    • Integer upscales work exactly as before, with bit-identical output.

    What changes in your results

    • Images from newer models (fractional grid): the correct resolution, with no doubled rows or columns.
    • Hand-drawn AI pixel art (e.g. 10 of the 17 sample images): cleaner outlines and single-pixel details that used to smear (fur between an eye and an outline, a paw's L shape). The output size can differ by a cell or two from before, and cells may not be square.
    • Classic nearest-neighbour upscales: unchanged.

    CLI

    • unfake detect prints a fractional scale when it finds one (10.24). --integer restores the integer-only output. The manifest gains grid and integer_scale.
    • unfake downscale -s 10.24 accepts a fractional scale. The elastic grid is on by default (--no-elastic turns it off), and the manifest records elastic per axis.
    • Also new since v1.2.0 (v1.3.0 wasn't published as a release): the quantize subcommand with fixed palettes and a reserved chroma color (--reserve-color), and --manifest on every command, which builds up one JSON manifest across a pipeline.
    • Prebuilt binaries: Windows x86_64 and Linux x86_64 (static, musl).

    Assets

    • unfaker-1.4.0.zip: the browser tool (same archive as on itch.io).
    • unfake-cli-1.4.0-x86_64-pc-windows-msvc.zip, unfake-cli-1.4.0-x86_64-unknown-linux-musl.tar.gz: the CLI.

    Internal

    • unfake-core 0.3.0: fractional_grid_detect, grid_for_scale, elastic_bounds, downscale_grid, downscale_bounds. Downscale reducers now run on explicit cell spans.
    • Checked against the bghira corpus (integer accuracy unchanged, 293/300) and 400 resampled synthetic images with ground truth (no false fractional grids). New unit, golden and CLI integration tests.

    Full Changelog: https://github.com/jenissimo/unfake.js/compare/v1.2.0...v1.4.0

  2. v1.2.0v1.2.0 — Rust/WebAssembly core2026-06-09 · 2026-06-09 16:42 UTC
    查看更新说明

    The image-processing pipeline now runs in unfake-core, a headless Rust crate compiled to WebAssembly for the browser tool and to a native binary for a new CLI. OpenCV.js and several JS dependencies are gone — the tool starts faster, ships lighter, and the same engine powers browser, CLI, and library.

    Highlights

    • New Rust to WASM core (crates/unfake-core): scale detection, grid snapping, downscaling, morphological cleanup, color quantization, content-adaptive downscaling, vector pre/post filters, and PNG encoding — all in one place.
    • OpenCV.js removed entirely. No ~10 MB WASM download on first process; noticeably faster cold start.
    • New native CLI for headless / batch use.

    Performance

    • The pixel-art pipeline (detect, snap, downscale, cleanup, quantize, encode) runs in the WASM core with no OpenCV load.
    • Content-adaptive downscaling is dramatically faster (about (scale/3)^2 less work, roughly 16x at scale 12) via an area pre-shrink before the EM, with no visible quality loss.

    Added

    • qvote downscale method: quantize to a palette, then vote per cell. Cleans up the muddy averaged colors nearest leaves on mixel / soft AI edges.
    • Processing spinner in the Result area (replaces the old text/hourglass progress).

    Changed (output may differ)

    • Color quantization now uses imagequant (libimagequant) instead of image-q. Palettes are generally better but will differ from previous results.
    • Content-adaptive output differs slightly (Rust EM + pre-shrink).
    • Default scale detection is now edge (more robust on real AI pixel art) instead of the runs-first auto routing. auto is still selectable.

    Removed

    • Dependencies: opencv.js (~10 MB), UPNG.js, pako, image-q, svd-js. Vendored runtime is now imagetracer.js (vectorizer) + tweakpane (UI) + the WASM core.

    Internal

    • Cargo workspace: unfake-core (lib), unfake-cli, unfake-wasm.
    • Golden and cross-runtime parity tests; CI for cargo test, a wasm32 compile check, and the core glue test.

    Note for existing users: because color quantization and content-adaptive downscaling use different (Rust) implementations now, processed output — especially palettes — may look different from v1.1.x. This is expected; the new results are generally cleaner.

    Full Changelog: https://github.com/jenissimo/unfake.js/compare/v1.1.0...v1.2.0

  3. v1.1.02026-06-08 · 2026-06-08 14:51 UTC
    查看更新说明

    Layers mode - extract mask + details layers for character customization (huge thanks to @MuhammedAlkhudiry for the PR). Includes Pixel Art First pre-processing and separate downloads for tint areas vs outlines/shadows.

    OpenCV is stable again - upstream is moving toward OpenCV 5, and the CDN OpenCV.js build we relied on started breaking scale detection and processing. We pinned OpenCV 4.12, vendored it with the app, and moved it into a Web Worker so the tab no longer freezes for 20–40 seconds on first Process.

    Quantization - Max Colors slider now goes up to 1024 (max value = no color reduction). Faster nearest-color mapping for large palettes. Auto-detect still caps at 32 by design.

    Polish — live progress log in the Result panel

    Please hard-refresh (Ctrl+Shift+R / Cmd+Shift+R) before testing. Bugs → itch comments or GitHub issues.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    unfake.js

    unfake.js is a versatile JavaScript library designed to bridge the gap between AI-generated images and clean, usable assets. It offers two primary modes of operation: a powerful Pixel Art Processor and a sophisticated Image Vectorizer. The library is bundled with a feature-rich browser-based tool for easy, interactive use.

    Browser Tool Screenshot for Pixel Art Browser Tool Screenshot for Vectorize

    Deep-Dive Articles

    Want to learn more about how it works under the hood?
    Check out these in-depth articles on the pixel art cleanup pipeline:

    Integrations & Online Demo

    • Try it online: unfaker on itch.io — browser-based demo, no install required.

    • ComfyUI Node: ComfyUI-Unfake-Pixels — use unfake.js directly in your ComfyUI workflows.

    • Python Port: unfake.py — A blazing fast Python implementation with Rust-accelerated quantization, offering a 10-20% speedup over the JS version.


    Features

    1. Pixel Art Processor

    This mode is tailored for cleaning up pixel art, especially pieces generated by AI that often suffer from inconsistent pixel sizes, color bleeding, and other artifacts.

    • Intelligent Scale Detection: Automatically detects the "true" pixel size of an upscaled pixel art image using runs-based or edge-aware algorithms, including fractional grids from models that resample their canvas (e.g. 200 cells at 2048 px = 10.24 px per cell). It can also accept a manual scale factor.
    • Content-Aware Downscaling: Provides multiple high-quality downscaling methods (dominant, median, content-adaptive, etc.) to reduce the image to its native 1x scale without introducing new colors or blurriness.
    • Grid Snapping: Automatically crops the image to align it perfectly with the detected pixel grid, ensuring clean edges. Fractional grids are sampled in place, cell by cell, and where hand-drawn cells jitter around the scale an elastic grid fits the cell boundaries to the drawn edges.
    • Color Quantization: Reduces the color palette to a specified maximum number of colors using imagequant (libimagequant) in the WASM core, with support for fixed custom palettes.
    • Artifact Cleanup: Includes optional post-processing steps like morphological cleanup (to fill holes and remove noise) and jaggy cleanup.
    • Alpha Channel Processing: Supports alpha binarization to create sharp, clean transparency.

    2. Image Vectorizer

    This mode converts raster images (PNG, JPG) into clean, scalable SVG files. It's an intelligent wrapper around imagetracer.js with extensive pre- and post-processing capabilities powered by the unfake-core WASM filters.

    • Noise Reduction Pre-Processing: Applies filters like Bilateral or Median blur before vectorization to reduce noise and create smoother outlines.
    • Smart Color Quantization: Reduces and simplifies the color palette before tracing for cleaner vector shapes. It can even auto-detect the optimal number of colors.
    • Background Handling: Intelligently handles transparent images by adding a temporary background during processing to prevent edge artifacts, which is then removed from the final SVG.
    • Post-Quantization Smoothing: Applies a gentle blur after color reduction to soften jagged edges before the final trace.
    • Fine-Tuned Tracing: Exposes detailed imagetracer.js options for fine-grained control over the final vector output.
    • Palette Extraction: Extracts the final color palette from the generated SVG.

    Browser Tool

    The project includes a browser-based tool (/browser-tool) that provides a user-friendly interface for all of the library's features.

    • Dual Modes: Easily switch between Pixel Art and Vectorization modes.
    • Live Settings Control: Use the Tweakpane panel to adjust all processing parameters in real-time.
    • Drag-and-Drop & Paste: Upload images by dragging them onto the window, selecting a file, or pasting directly from the clipboard.
    • Before/After View: Instantly see the original and processed images side-by-side.
    • Magnifier Tool: A built-in magnifying glass to inspect pixel-level details on both the original and result images.
    • Palette Editor: View the result's color palette and interactively replace colors.
    • Download & Copy: Download the final asset (.png for pixel art, .svg for vector) or copy it directly to the clipboard.

    How to Use

    Running the Browser Tool Locally

    ⚠️ You need a local server!

    Modern browsers do not allow ES module imports (importmap, type="module") from local files (file://). To use the browser tool, you must run it via a local http(s) server.

    Quick ways to start a server:


    1. Start a local server using one of the methods above.
    2. Open http://localhost:8080/browser-tool/ in your browser (or the port you chose).
    3. Upload an image, tweak the settings, enjoy!

    Using the Library (unfake.js) in Your Own Project

    The library is written as ES modules. You can import and use its core functions processImage and vectorizeImage.

    1. Pixel Processing Example:

    import unfake from './lib/index.js';
    
    const fileInput = document.getElementById('my-file-input');
    const file = fileInput.files[0];
    
    const options = {
        file: file,
        maxColors: 32,
        detectMethod: 'auto', // 'auto', 'runs', 'edge'
        downscaleMethod: 'dominant',
        snapGrid: true,
        cleanup: { 
            morph: true, 
            jaggy: true 
        }
    };
    
    try {
        const { png, imageData, palette, manifest } = await unfake.processImage(options);
        
        // `png` is a Uint8Array of the final PNG file
        const blob = new Blob([png], { type: 'image/png' });
        const url = URL.createObjectURL(blob);
        
        // Now you can use the URL for an <img> tag or download link
        document.getElementById('result-image').src = url;
    
    } catch (error) {
        console.error("Pixel processing failed:", error);
    }
    

    2. Vectorization Example:

    import unfake from './lib/index.js';
    
    const fileInput = document.getElementById('my-file-input');
    const file = fileInput.files[0];
    
    const options = {
        file: file,
        preProcess: {
            enabled: true,
            filter: 'bilateral',
            value: 15
        },
        quantize: {
            enabled: true,
            maxColors: 'auto' // or a number like 16
        },
        // imagetracer.js options
        ltres: 1,
        qtres: 1,
    };
    
    try {
        const { svg, palette, manifest } = await unfake.vectorizeImage(options);
        
        // `svg` is a string containing the SVG markup
        document.getElementById('result-container').innerHTML = svg;
    
    } catch (error) {
        console.error("Vectorization failed:", error);
    }
    

    Architecture

    The image-processing core lives in unfake-core, a headless Rust crate compiled to WebAssembly for the browser tool and to a native binary for the CLI (crates/; unfake detect / snap / downscale / quantize, with fixed palettes, a reserved chroma color, and a JSON pipeline manifest). It owns scale detection (integer, fractional and elastic cell grids), grid snapping, downscaling (dominant / median / mode / mean / qvote), morphological cleanup, color quantization (imagequant), content-adaptive downscaling, the vector pre/post filters, and PNG encoding — no OpenCV. The JavaScript layer in browser-tool/ is a thin interface: file I/O, canvas, the Tweakpane UI, and calls into the WASM core.

    bun run core:wasm   # build the WASM core into browser-tool/vendor/unfake-core/
    bun run core:test   # cargo test
    bun run core:eval   # CLI scale-detection eval on the bghira corpus
    

    Core Dependencies

    • unfake-core (Rust → WebAssembly / native): The headless image-processing core (see Architecture). Uses imagequant for quantization and the png crate for encoding.
    • ImageTracer.js: The engine for the vectorization (raster → SVG) process.
    • Tweakpane: The interactive settings UI in the browser tool.

    License

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