@madeitpx/pixelart

中文文档
0.2.1发布于 2026/11/02MPL-2.0TypeScriptESM + CJS构建来源已验证

Node.js binding for the madeitpx pixel-art image conversion library

原始使用文档

@madeitpx/pixelart

madeitpx

Node.js binding for madeitpx. Converts RGBA8 pixel buffers to an output grid with a limited color palette.

madeitpx conversion examples

npm install @madeitpx/pixelart

The package installs a native library for supported platforms: Windows x64 and ARM64, Linux x64 and ARM64 (glibc), and macOS x64 and ARM64. The matching platform package is an optional dependency and is selected automatically. For local builds or custom locations, pass libraryPath when creating a converter or set MADEITPX_LIBRARY_PATH.

const { createConverter } = require('@madeitpx/pixelart');

const convert = createConverter();

const rgba = Buffer.from([
  255, 0, 0, 255,
  0, 255, 0, 255,
  0, 0, 255, 255,
  255, 255, 255, 255
]);
const result = convert(rgba, {
  inputWidth: 2,
  inputHeight: 2,
  targetWidth: 1,
  targetHeight: 1
});

The result is a Buffer containing tightly packed RGBA8 pixels, opaque except for the transparent cells that the pixelart preset can keep (see below). Input rows may include padding by setting inputStride. Conversion options include preset, paletteColors, backgroundRgb, sampling, clusterCleanup and pixelart. The defaults are balanced palette, nearest sampling, black background, and cluster cleanup enabled.

Pixelart preset

preset: 'pixelart' uses version 2 of the pixel-art pipeline: it recovers the real grid of pixel art that was scaled up, and reduces smooth artwork with preserved outlines. pixelart holds the detailed settings; any setting you leave out keeps the library default.

const out = convert(rgba, {
  inputWidth: 1024,
  inputHeight: 1536,
  targetWidth: 256,
  targetHeight: 384,
  preset: 'pixelart',
  pixelart: { mode: 'illustration', paletteMax: 32, minRegion: 4 }
});

const defaults = convert.pixelartDefaults();
const original = convert(rgba, { ...settings, preset: 'pixelart', pixelart: { version: 1 } });

convert.pixelartDefaults() returns every default, so a settings panel can reset a field by reading it from there. version: 1 runs the original pipeline. Settings: version, mode (auto, grid, illustration), gridFit, gridSearchPermille, sampleInsetPercent, colorTolerance, paletteMax, refineIterations, inkPercent, minRegion, alphaThreshold and keepTransparency. With keepTransparency (default) cells that were transparent in the source come back with alpha 0. See the pixelart documentation.

Browsers and bundlers

The package also runs in the browser without a native library. Bundlers (Vite, webpack, Astro) pick the WebAssembly entry through the browser export condition, and createConverter is asynchronous there:

import { createConverter } from '@madeitpx/pixelart';

const convert = await createConverter();
const image = ctx.getImageData(0, 0, width, height);
const out = convert(image.data, {
  inputWidth: width,
  inputHeight: height,
  targetWidth: 128,
  targetHeight: 128,
  preset: 'pixelart'
});
ctx2.putImageData(new ImageData(new Uint8ClampedArray(out), 128, 128), 0, 0);

The module is loaded from wasm/madeitpx.wasm next to the package. To host it yourself, pass createConverter({ wasm: url }) where url is a URL, Response, ArrayBuffer or WebAssembly.Module; @madeitpx/pixelart/madeitpx.wasm resolves to the file for bundlers.

Node.js 18 or newer is required.

版本与发布记录

@madeitpx/pixelart 共发布 6 个版本,首次发布于 2026/10/17;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.1latest2026/11/021 天前
0.2.02026/10/313 天前
0.1.22026/10/304 天前
0.1.12026/10/1717 天前
0.1.02026/10/1717 天前
0.0.0-stage2026/10/1717 天前

关于 @madeitpx/pixelart 的常见问题

@madeitpx/pixelart 是什么?

Node.js绑定madeitpx像素图像转换库

如何安装 @madeitpx/pixelart?

在项目目录运行 npm install @madeitpx/pixelart,或使用 pnpm add / yarn add / bun add。

@madeitpx/pixelart 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@madeitpx/pixelart 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@madeitpx/pixelart 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@madeitpx/pixelart 可以商用吗?

@madeitpx/pixelart 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@madeitpx/pixelart 还在维护吗?

最新版本 0.2.1 发布于 2026/11/02(1 天前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/10/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。