gm-image-tile

    0.1.0 • Public • Published

    gm-image-tile NPM Version

    Creates image tiles in Node.js using GraphicsMagick.

    Install

    First, install GraphicsMagick. This is part of requirement for 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.

    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, as follow. Notes the bottommost tiles are truncated and height is 256 pixels.

    [
      [
        { buffer: <Buffer>, x: 0,   y: 0, width: 512, height: 512 },
        { buffer: <Buffer>, x: 512, y: 0, width: 512, height: 512 }
      ], [
        { buffer: <Buffer>, x: 0,   y: 512, width: 512, height: 256 },
        { buffer: <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.

    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 and npm.

    Bugs or suggestions? Please file us an issue.

    Keywords

    none

    Install

    npm i gm-image-tile

    DownloadsWeekly Downloads

    2

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • compulim
    • spyip