@madeitpx/pixelart

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

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

中文使用文档

@madeitpx / pixelart

madeitpx

Node.js绑定 madeitpx. 转换 RGBA8像素缓冲到具有有限调色板的输出网格。

madeitpx conversion examples

npm install @madeitpx/pixelart

该包为支持的平台安装一个本机库:Windows x64和Windows x64 ARM64, Linux x64和ARM64 (glibc), macOS x64和ARM64。匹配的 平台包是一个可选的依赖项,会被自动选中。 对于本地构建或自定义位置,请忽略 libraryPath 在创建 转换器或机组 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
});

结果是 Buffer 包含紧密包装的RGBA8像素,除透明外不透明 像素预设可以保留的单元格(见下文)。输入行可以通过设置包括填充 inputStride. 转换选项包括 preset, paletteColors, backgroundRgb, sampling, clusterCleanup 和 pixelart. 默认值是平衡调色板,最接近采样,黑色 后台,并启用集群清理。

Pixelart预设

preset: 'pixelart' 使用版本2的像素-艺术管道:它恢复像素的真实网格 艺术品按比例放大,并减少平滑的艺术品,保留轮廓。 pixelart 拥有 详细的设置;您遗漏的任何设置都将保留库的默认设置。

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() 返回每个默认值,因此设置面板可以通过 从这里开始读。 version: 1 运行原始管道。设置: version, mode (auto, grid, illustration), gridFit, gridSearchPermille, sampleInsetPercent, colorTolerance, paletteMax, refineIterations, inkPercent, minRegion, alphaThreshold 和 keepTransparency. 与 keepTransparency (默认)源中透明的单元格 得到0。看到 pixelart文档.

浏览器和捆绑器

该包也可以在没有本机库的情况下在浏览器中运行。捆绑器(Vite, webpack, Astro) 选项中选择WebAssembly条目 browser 出口条件;及 createConverter 是 异步:

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);

加载模块 wasm/madeitpx.wasm 包裹旁边。自己托管,不需要 createConverter({ wasm: url }) 哪里 url 是URL, Response, ArrayBuffer 或者 WebAssembly.Module; @madeitpx/pixelart/madeitpx.wasm 解析为绑定器的文件。

需要Node.js 18或更新版本。

版本与发布记录

@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 和提交记录判断。