sharpsmith
v1.1.5
Published
A spritesmith engine powered by sharp.
Maintainers
Readme
sharpsmith
基于 sharp 的 spritesmith 引擎,支持 Node.js 22 及更高版本。
完整双语文档请查看 docs/。
安装
pnpm add sharpsmith作为 Spritesmith 引擎使用
const Spritesmith = require("spritesmith");
const SharpSmith = require("sharpsmith");
Spritesmith.run(
{
src: ["icons/home.png", "icons/settings.png"],
engine: SharpSmith,
algorithm: "binary-tree",
padding: 4,
},
(error, result) => {
if (error) throw error;
// result.image 是生成的 readable stream
// result.coordinates 是每张源图的位置和尺寸
// result.properties 是 sprite sheet 的尺寸
},
);直接使用 Engine API
import SharpSmith from "sharpsmith";
const engine = new SharpSmith({ concurrentFileLimit: 4 });
engine.createImages(["a.png", "b.png"], (error, images) => {
if (error) throw error;
const canvas = engine.createCanvas(128, 128);
canvas.addImage(images[0], 0, 0);
canvas.addImage(images[1], 32, 0);
canvas.export({ format: "png" }).pipe(process.stdout);
});支持的导出格式:png、jpg、jpeg 和 gif。输入支持文件路径、Vinyl
Buffer 和 Vinyl readable stream。
Playground
使用内置图标运行单个分类:
pnpm playground
pnpm playground -- playground/sprites/payment一次生成所有分类:
pnpm playground:all输出目录格式:
playground/generated/<category>/<category>.png
playground/generated/<category>/<category>.json开发
pnpm install
pnpm lint
pnpm typecheck
pnpm test
pnpm build更多内容请查看:
