sprite-me
v1.1.6
Published
Core for spritesheet generation based on ImageMagick
Downloads
21
Maintainers
Readme
Sprite-me
The spritesheet creation tool for Node.js
SpriteMe designed as core module which do not create or modify any files.
If you want build sprites during build procces look at Sprite-me webpack plugin
Installation
Install ImageMagic V7.
Version
7
is required. Check it by runningmagick --version
I recomend to use ImageMagick Easy Instal
Some package managers likebrew
can install imagemagick with version 6Install package:
npm i -s sprite-me
.
Usage
Base usage spriteMe(images: string[], options?: Object)
.
Returns object with next keys:
image
- Buffer with generated spriteframes
- Frames objectmeta
- Meta information Object
Script example to create and save sprite:
const fs = require('fs');
const spriteMe = require('sprite-me');
const imageName = 'spriteMe.png';
const jsonName = 'spriteMe.json'
const images = ['./img1.png', './img2.png'];
(async () => {
const { meta, frames, image } = await spriteMe(images);
const json = JSON.stringify({
meta: {
...meta,
image: imageName,
},
frames,
});
fs.writeFileSync(imageName, image);
fs.writeFileSync(jsonName, json);
})();
Options
Options can be passed as second argument
spriteMe(images, { format: 'jpg', gap: 100 })
format
- Defaultpng
- Format of compiled image.gap
- Default10
- Distance beetween images.