You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Parse Aseprite files with Node.js, no external dependencies.
Install
To install for use:
npm i ase-parse
Instructions
You'll probably want to get the Buffer of the Aseprite file in whatever way you feel like. For the example, we'll just use fs.readFileSync(). But you can get it from a network request, etc.
After parsing, you can get the data and do something like generate an image with the sharp npm lib, which accepts raw pixel data and supports image composition.
Here is a more advanced example generating a png image of the first frame using the sharp lib.
constAseprite=require('ase-parser');constfs=require('fs');constsharp=require('sharp');asyncfunctionmakePNG(){constbuff=fs.readFileSync('./my_chocobo.aseprite');constase=newAseprite(buff,'my_chocobo.aseprite');ase.parse();// Create a blank png image buffer that's the same size as the Aseprite sprite (only make the promise because we'll use Promise.all a little later)constbgPromise=sharp({create: {width: ase.width,height: ase.height,channels: 4,background: {r: 0,g: 0,b: 0,alpha: 0}}}).png().toBuffer();// Get the cels for the first frameconstcels=ase.frames[0].cels// copy the array.map(a=>a).sort((a,b)=>{constorderA=a.layerIndex+a.zIndex;constorderB=b.layerIndex+b.zIndex;// sort by order, then by zIndexreturnorderA-orderB||a.zIndex-b.zIndex;})// Create png image buffers per cel to create an image of the first frame (creating the Promises to be used)constotherPromises=cels.map(cel=>{returnsharp(cel.rawCelData,{raw: {width: cel.w,height: cel.h,channels: 4}}).png().toBuffer();});// Run the promises all at once to get the buffers for the base image and the cels to combineconst[bg, ...others]=awaitPromise.all([bgPromise, ...otherPromises]).catch(console.log);// take the first image and add on the png buffers on top of it (the cels should be in order from bottom to top from the parse)constfinalBuff=awaitsharp(bg).composite(others.map((img,index)=>({input: img,top: cels[index].ypos,left: cels[index].xpos}))).png().toBuffer();// saves the file as a png with the buffer from sharp.compositefs.writeFileSync(ase.name.replace('.aseprite','.png'),finalBuff);}makePNG();
Aseprite Functions
constructor
Parameters:
buffer: Expects a Node.js Buffer of the Aseprite file.
name: Expects a string that's the name of the Aseprite file, including the extension.