# unfake.js

> Clean up AI pixel art and turn AI images into SVG, in the browser

- Category: Multimodal Generation / Image Generation
- Language: JavaScript, Rust
- Licence: MIT
- Repository: https://github.com/jenissimo/unfake.js
- Website: https://jenissimo.itch.io/unfaker
- Canonical page: https://ai-tldr.dev/tools/unfake-js/
- Updated: 2026-09-29

## In short

unfake.js cleans up images that come out of AI image generators so they can be used as real assets. It sits in the Image Generation category of the Multimodal Generation tools and is open-source, written in JavaScript, Rust and licensed MIT. To get started: serve the browser tool locally.

## Overview

unfake.js cleans up images that come out of AI image generators so they can be used as real assets. Models asked for pixel art usually return a large upscaled picture whose "pixels" are uneven blocks with blurred edges and stray colours; models asked for a logo return a raster file when a designer needs a vector. unfake.js has one mode for each problem: a Pixel Art Processor and an Image Vectorizer.

The Pixel Art Processor works out the true pixel size of an upscaled image, snaps it to that grid and downscales it to its native 1x size without adding new colours, then reduces the palette to a maximum you set with libimagequant. Since v1.4.0 (September 2026) it also handles fractional grids, such as 200 cells drawn at 2048 px (10.24 px per cell), and an elastic grid that follows hand-drawn cells whose size wanders. The Image Vectorizer wraps imagetracer.js, with noise filtering and colour quantization before tracing, so a PNG or JPG comes out as a cleaner SVG.

The processing core, unfake-core, is a Rust crate compiled to WebAssembly for the browser and to a native binary for the `unfake` command-line tool. The browser tool runs entirely on the client, with drag-and-drop or paste input, live settings, a before/after view, a magnifier and a palette editor; a hosted copy runs on itch.io. The project is MIT-licensed, and the README links a ComfyUI node and a Python port maintained by other developers.

## What it does

- Scale detection that finds the real cell size of upscaled pixel art, including fractional grids from models that resample their canvas and an elastic grid for hand-drawn cells
- Grid snapping and content-aware downscaling (`dominant`, `median`, `mode`, `mean`, `content-adaptive` and more) that bring an image to 1x without introducing new colours
- Palette reduction with libimagequant, fixed custom palettes, and a reserved chroma colour that stays bit-exact
- Optional cleanup passes: morphological hole-filling and noise removal, jaggy cleanup, and alpha binarization for hard-edged transparency
- A raster-to-SVG vectorizer built on imagetracer.js, with bilateral or median pre-filtering, automatic colour counts and palette extraction
- Three ways to run it: a browser tool (hosted on itch.io or served locally), ES-module library functions `processImage` and `vectorizeImage`, and a native `unfake` CLI with a shared JSON manifest

## Getting started

The quickest path is the hosted browser tool on itch.io, which needs no install. To run it yourself or call it from code, follow the README; the CLI commands come from the v1.4.0 release notes and the CLI's own argument definitions.

1. Serve the browser tool locally

   Browsers block ES module imports from `file://`, so the README says to serve the repository over HTTP and then open `http://localhost:8080/browser-tool/`. Drop or paste an image, adjust the settings, and download a PNG (pixel art) or SVG (vector).

```bash
git clone https://github.com/jenissimo/unfake.js
cd unfake.js
python3 -m http.server 8080
# or: npx http-server -p 8080
```

2. Clean up pixel art from code

   The library is plain ES modules. `processImage` returns the final PNG bytes along with the image data, the palette and a manifest.

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

const { png, palette, manifest } = await unfake.processImage({
  file,
  maxColors: 32,
  detectMethod: 'auto', // 'auto', 'runs', 'edge'
  downscaleMethod: 'dominant',
  snapGrid: true,
  cleanup: { morph: true, jaggy: true },
});

const url = URL.createObjectURL(new Blob([png], { type: 'image/png' }));
```

3. Vectorize an image

   `vectorizeImage` returns SVG markup and the palette it used. The pre-processing filter and the colour quantization step are both optional.

```js
const { svg, palette } = await unfake.vectorizeImage({
  file,
  preProcess: { enabled: true, filter: 'bilateral', value: 15 },
  quantize: { enabled: true, maxColors: 'auto' },
  ltres: 1,
  qtres: 1,
});

document.getElementById('result-container').innerHTML = svg;
```

4. Batch it with the CLI

   Each GitHub release ships prebuilt `unfake` binaries for Windows x86_64 and Linux x86_64. `detect` prints the cell size (fractional when it finds one), `downscale` samples the image at that size, and `quantize` caps the palette; `--manifest` collects one JSON record across the steps.

```bash
unfake detect sprite.png --manifest sprite.json
unfake downscale sprite.png -s 10.24 -o sprite-1x.png --manifest sprite.json
unfake quantize sprite-1x.png -c 16 -o sprite-16.png --manifest sprite.json
```

## When to use it

- Turn a sprite or tile from an image model into a true 1x pixel-art asset with a fixed palette, ready for a game engine
- Re-grid pixel art from newer models whose cells are fractional or hand-drawn, without doubled rows or dropped pixels
- Convert an AI-generated logo or illustration into an SVG you can scale and edit
- Run the same cleanup over a folder of generated sprites from a script with the native CLI

## Version history

- 2026-09-29 v1.4.0: Scale detection learned fractional grids (for models that resample an N×N canvas) and an elastic grid for hand-drawn cells, on by default. The CLI gained fractional `detect`/`downscale`, a `quantize` subcommand with fixed palettes, and `--manifest` on every command.
