Creates image tiles in Node.js using GraphicsMagick.
npm install gm-image-tilenpm install gm-image-tile --save.
otters.jpg with tile size of 512 pixels. Call imageTile in a Promise-fashion. By default, the output is in PNG format of type Buffer.
js
const imageBuffer = fs.readFileSync('otters.jpg');
imageTile(imageBuffer, 512).then(result => {
// Further processing here
});
`
$3
Assumes the input image is 1024x768 and tile size is set to 512 pixels. After calling imageTile, the result will be returned as Buffer, as follow. Notes the bottommost tiles are truncated and height is 256 pixels.
`js
[
[
{ buffer: , x: 0, y: 0, width: 512, height: 512 },
{ buffer: , x: 512, y: 0, width: 512, height: 512 }
], [
{ buffer: , x: 0, y: 512, width: 512, height: 256 },
{ buffer: , x: 512, y: 512, width: 512, height: 256 }
]
]
`
$3
By default, the output tiles are in PNG format. To output in JPEG format of quality level 80, you can call imageTile as below.
`js
const options = {
format: 'JPG',
quality: 80
}
imageTile(imageBuffer, 512, options).then(result => {
// Output buffers will be JPEG images of quality level 80
});
``