https://github.com/compulim/gm-image-tile
Creates image tiles with Graphicsmagick in Node.js
https://github.com/compulim/gm-image-tile
Last synced: about 1 month ago
JSON representation
Creates image tiles with Graphicsmagick in Node.js
- Host: GitHub
- URL: https://github.com/compulim/gm-image-tile
- Owner: compulim
- License: mit
- Created: 2017-01-04T09:17:45.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-04T09:48:42.000Z (over 8 years ago)
- Last Synced: 2025-03-24T16:02:52.044Z (about 2 months ago)
- Language: JavaScript
- Size: 806 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# gm-image-tile [](https://www.npmjs.org/package/gm-image-tile)
Creates image tiles in Node.js using GraphicsMagick.
## Install
First, install [GraphicsMagick](https://graphicsmagick.org). This is part of requirement for [gm](https://npmjs.org/package/gm) package.
Then, install this package by `npm install gm-image-tile --save`.
## Usage
To create image tiles from file `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](https://nodejs.org/api/buffer.html).
```js
const imageBuffer = fs.readFileSync('otters.jpg');imageTile(imageBuffer, 512).then(result => {
// Further processing here
});
```### Result from `imageTile` call
Assumes the input image is 1024x768 and tile size is set to 512 pixels. After calling `imageTile`, the result will be returned as [Buffer](https://nodejs.org/api/buffer.html), 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 }
]
]
```### Options
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
});
```## Contribution
Like us? Please star us in [GitHub](https://github.com/compulim/gm-image-tile/stargazers) and [npm](https://npmjs.com/package/gm-image-tile).
Bugs or suggestions? Please [file us an issue](https://github.com/compulim/gm-image-tile/issues).