pencil-js / spritesheet Goto Github PK
View Code? Open in Web Editor NEW🥤 Pack images into a spritesheet.
License: MIT License
🥤 Pack images into a spritesheet.
License: MIT License
Adding 1 (or more ?) pixels around each tiles with the same color as the pixel next to it can avoid tiles edges being poisoned by the outer edges.
This is out of scope for now, but if some people need it, I'll consider adding it.
Some texture are limited in size, in this case it can be great to output multiple spritesheet according to a max-width or max-height option.
This is out of scope for now, but if some people need it, I'll consider adding it.
Hey, I just tried the usage example and I got a few errors on node v14.15.0:
Must use import to load ES Module
ReferenceError: writeFileSync is not defined
Here is a fixed version:
import spritesheet from "@pencil.js/spritesheet";
import fs from "fs";
// List of files to pack
const files = ["image1.png", "image2.jpg", "image3.gif"];
const options = {
outputFormat: "png",
};
// Call the async function and extract the json and image values
(async () => {
const { json, image } = await spritesheet(files, options);
// Write the files (for example)
fs.writeFileSync("example.png", image);
fs.writeFileSync("example.json", JSON.stringify(json));
})();
Since you use .mjs
I also had to add "type": "module"
to my package.json.
Also, this line throws an error Unknown file extension ".json"
for me. This may be related to mjs, where importing json is still experimental (https://nodejs.org/api/esm.html#esm_json_modules).
Line 4 in e5014f3
After fixing that and trying to load the spritesheet with PIXI.js I noticed the JSON is missing the meta.image
property, which is expected by PIXI to reference the spritesheet file name.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.