# @madeitpx/pixelart 中文文档

规范地址：https://npmcn.com/package/%40madeitpx/pixelart/

版本：0\.2\.1
npm 元数据更新时间：2026-11-01T18:39:49.260Z
中文译文更新时间：2026-11-01T19:19:28.652Z
软件包许可：MPL-2\.0

本文由上游 README 机器翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40madeitpx/pixelart
原文对照：https://npmcn.com/package/%40madeitpx/pixelart/?lang=original
项目主页：https://github.com/TamKungZ/madeitpx#readme
源码仓库：https://github.com/TamKungZ/madeitpx

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：88.3 kB，8 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=18
- 运行依赖：1 个
- 首次发布：2026-10-17T08:58:11.139Z
- 最新版本发布：2026-11-01T18:39:48.797Z
- 已发布版本数：6（近 12 个月 6 个）

## 中文简介

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

## 安装

```sh
npm install @madeitpx/pixelart
```

也可以使用：`pnpm add @madeitpx/pixelart`、`yarn add @madeitpx/pixelart`、`bun add @madeitpx/pixelart`

## README

# @madeitpx / pixelart

![madeitpx](https://raw.githubusercontent.com/TamKungZ/madeitpx/main/assets/logo-wordmark.png)

Node.js绑定 [madeitpx](https://github.com/TamKungZ/madeitpx)． 转换 RGBA8像素缓冲到具有有限调色板的输出网格。

![madeitpx conversion examples](https://raw.githubusercontent.com/TamKungZ/madeitpx/main/test_sources/output/preview.png)

```sh
npm install @madeitpx/pixelart
```

该包为支持的平台安装一个本机库：Windows x64和Windows x64 ARM64， Linux x64和ARM64 (glibc)， macOS x64和ARM64。匹配的 平台包是一个可选的依赖项，会被自动选中。 对于本地构建或自定义位置，请忽略 `libraryPath` 在创建 转换器或机组 `MADEITPX_LIBRARY_PATH`.

```js
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` 拥有 详细的设置;您遗漏的任何设置都将保留库的默认设置。

```js
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文档](https://npmcn.com/package/docs/PIXELART.md).

## 浏览器和捆绑器

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

```js
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 是什么？

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

