@fast-pixel/clip
Clip Pixels
install
npm install @fast-pixel/clip
usage
clipping png file
If we wanted to remove two pixels from the edge of the image.
const fs = require("fs");
const readPNG = require("read-png");
const clip = require("@fast-pixel/clip");
const png = await readPNG({ data: fs.readFileSync("./flower.png") });
const clipping = clip({
data: png.pixels, // numerical array of pixel values
/*
dimensions of the output / clipping
1: all the pixels are interleaved like r0,g0,b0,a0,r1,g1,b1,a1,...
2: an array of band values where [ [r0, r1, r2, ...], [g0, g1, g2, ...] ]
3: by band then row the column [ [ b0r0c0, b0r0c1 ] ... ]
*/
ndim: 3,
top: 2, // how far from the top to start clipping
bottom: png.height - 2, // how far from the top to stop clipping
left: 2, // how far from the left to start clipping
right: png.width - 2 // how far from the left to start clipping
height: png.height // height of the input image
width: png.width // width of the input image
})