https://github.com/zprodev/9-slicer
Convert PNG to 9slice
https://github.com/zprodev/9-slicer
esmodules nine-patch nineslice
Last synced: 3 months ago
JSON representation
Convert PNG to 9slice
- Host: GitHub
- URL: https://github.com/zprodev/9-slicer
- Owner: zprodev
- License: mit
- Created: 2018-08-14T12:50:43.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-08-03T20:35:32.000Z (almost 4 years ago)
- Last Synced: 2025-03-29T16:02:07.659Z (4 months ago)
- Topics: esmodules, nine-patch, nineslice
- Language: TypeScript
- Homepage:
- Size: 647 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 9-slicer
[](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
## Examples
### input

### output
Sliced PNG

Parameters
```
{ width: 420,
height: 240,
left: 46,
right: 45,
top: 48,
bottom: 48 }
```## Demo
[9 SLICER](https://zprodev.github.io/9-slicer/demo/)
## Distribution
### npm
```
npm i -D 9-slicer
```### files
[for CommonJS](https://github.com/zprodev/9-slicer/tree/master/dist/cjs)
[for Browser](https://github.com/zprodev/9-slicer/tree/master/dist/browser)
[for ESModules](https://github.com/zprodev/9-slicer/tree/master/dist/esm)
## Usage
### for CommonJS
```
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));
}
```