1.0.1 • Published 12 months ago

node-merge-images v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

node-merge-images

Merges images. You can optionally set the merging orientation (vertical or horizontal), margins between images, etc.

Click here to see the change log.

Supported OS

  • Linux
  • MAC

Requirements

Requires imagemagick CLI tools to be installed.

  • For instance, if you're on OS X you can use Homebrew.
    brew install imagemagick
  • For Linux, use yum.
    sudo yum -y install ImageMagick

Installation

npm install --save node-merge-images

Image Merging API

Usage

  • Merge vertically.

    const merge = require('node-merge-images');
    
    await merge(['1.jpg', '2.jpg', '3.jpg'], 'out.jpg');
  • Merge horizontally.

    const merge = require('node-merge-images');
    
    await merge(['1.jpg', '2.jpg', '3.jpg'], 'out.jpg', {direction: 'horizontal'});
  • Merge vertically with 30px spacing.
    In the example, the background color is set to #000 with the background option.

    const merge = require('node-merge-images');
    
    await merge(['1.jpg', '2.jpg', '3.jpg'], 'out.jpg', {offset: 30, background: '#000'});
  • Merge horizontally with 30px spacing.
    In the example, the background color is set to #000 with the background option.

    const merge = require('node-merge-images');
    
    await merge(['1.jpg', '2.jpg', '3.jpg'], 'out.jpg', {direction: 'horizontal', offset: 30, background: '#000'});
  • Merge images of different sizes vertically.
    The image width after merging will be adjusted to the image with the maximum width.

    const merge = require('node-merge-images');
    
    await merge(['1.jpg', '2.jpg', '3.jpg'], 'out.jpg');
  • Merge images of different sizes horizontally.
    The image height after merging will be adjusted to the image with the maximum height.

    const merge = require('node-merge-images');
    
    await merge(['1.jpg', '2.jpg', '5.jpg'], 'out.jpg', {direction: 'horizontal', offset: 30});

Parameters

  • {string[]} inputPaths Path list of images to merge.
  • {string} outputPath Output destination path for merged images.
  • {'vertical'|'horizontal'} options.direction? Direction of the merged image. Default is vertical.
  • {string} options.background?
    The background color of the merged image.
    This option accepts a color name, a hex color, or a numerical RGB, RGBA, HSL, HSLA, CMYK, or CMYKA specification.
    For example, blue, #dddddff, rgb(255,255,255), etc.
    Default is white.
  • {number} options.offset? Offset in pixels between each image. Default is 0.

Return value

{Promise<void>

Throws

  • {TypeError} Input path is not Array.
  • {TypeError} Input path is empty.
  • {TypeError} Output path is empty.
  • {TypeError} The direction option is not "vertical" or "horizontal".
  • {TypeError} Offset option is not greater than or equal to 0.
  • {TypeError} Input path file not found.
  • {Error} Error executing convert command.

Testing

With npm do:

npm test

Author

Takuya Motoshima

License

MIT