1.0.3 • Published 5 years ago

imagemagick-convert v1.0.3

Weekly downloads
318
License
MIT
Repository
github
Last release
5 years ago

imagemagick-convert

Node.js wrapper for ImageMagick CLI for simple converting images.

Prerequisites

  • Node.js >= 7.10.1
  • ImageMagick >= 6.9.5

Installation

With NPM:

npm install --save imagemagick-convert

With Yarn:

yarn add imagemagick-convert

ImageMagick installation (see more details):

OSCommand
OS Xbrew install imagemagick
Ubuntu/Debianapt-get install imagemagick
Centos/RHELyum install ImageMagick
Alpineapk add --update imagemagick

Example

import {readFileSync} from 'fs';
import {convert} from 'imagemagick-convert';

// somewhere in async function
const imgBuffer = await convert({
    srcData: readFileSync('./origin.jpg'),
    srcFormat: 'JPEG',
    width: 100,
    height: 100,
    resize: 'crop',
    format: 'PNG'
});

Original JPEG:

Original image

Converted to PNG and resized:

fitfillcrop
Original imageOriginal imageOriginal image

API reference

convert(options: Object):Promise<Buffer> - converts images

Options:

AttributeTypeRequiredDefaultDescription
srcDataBuffer*source image
srcFormatDictionaryauto-detectionsource file format (explicit specification), for more details see ImageMagick Supported Image Formats
widthIntegersource widthoutput image width in pixels
heightIntegersource heightoutput image height in pixels
resizeEnumcropstyle of resizing: crop, fit, fill
densityInteger600density/resolution for rendering an image from vector formats such as Postscript, PDF, WMF, SVG
backgroundStringnonebackground color or transparency for images
gravityDictionaryCentergravity option, for more details see ImageMagick gravity options
formatDictionarysource formatoutput file format, for more details see ImageMagick Supported Image Formats
qualityInteger75JPEG/MIFF/PNG compression level: 1 - 100
blurFloat0blur level: 0 - 1
rotateInteger0rotating degrees
flipBooleanfalsevertical flip