9-slicer
Version:
Convert PNG to 9slice
68 lines (44 loc) • 1.47 kB
Markdown
[](https://travis-ci.org/zprodev/9-slicer)
[](https://www.npmjs.com/package/9-slicer)
[](LICENSE)
Automatically judge the enlarged area and create 9 slice images

Sliced PNG

Parameters
```
{ width: 420,
height: 240,
left: 46,
right: 45,
top: 48,
bottom: 48 }
```
[](https://zprodev.github.io/9-slicer/demo/)
```
npm i -D 9-slicer
```
[](https://github.com/zprodev/9-slicer/tree/master/dist/cjs)
[](https://github.com/zprodev/9-slicer/tree/master/dist/browser)
[](https://github.com/zprodev/9-slicer/tree/master/dist/esm)
```
const { readFileSync, writeFileSync } = require('fs');
const { slice } = require('9-slicer');
const input = readFileSync('input.png');
const output = slice(input);
// Example of outputting only things that can be reduced by 30% or more
if(30 <= output.reduction){
writeFileSync('output.png', output.buffer);
writeFileSync('output.json', JSON.stringify(output.params));
}
```