Package Exports
- chop-image
- chop-image/imageSplitter.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (chop-image) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
chop-image
chop-image is an npm module which splits an image into chunks of given height. chop-image is inspired from split-images. Unlike split-images which uses jimp for processing image, chop-image uses high performing sharp for chopping images.
Supported Images
JPEG, PNG, WebP, AVIF, TIFF, GIF and SVG images.
npm
npm i chop-image --save
Node versions
Node >= 10
Methods
imageToChunks(image,chunkSize)
Splits the image horizontaly to chunks having height=chunkSize. Chunks are returned as array buffer.
returns
Array<Buffer>
Examples
Read from a local file
const fs = require('fs')
const imageSplitter = require('./imageSplitter.js')
;(async () => {
try {
const chunckSize = 500
const chuncks = await imageSplitter.imageToChunks(
'imgs/test.jpg',
chunckSize
)
console.log('Number of chunks', chuncks.length)
actions = []
console.log(chuncks)
let i = 0
chuncks.forEach(c => {
i++
actions.push(
fs.writeFile(`./imgs/slice_${i}.jpg`, c, function (err, result) {
if (err) console.log('error', err)
})
)
})
await Promise.all(actions)
} catch (e) {
console.log(e)
}
})()