Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

imagemagick-convert

izonder2.8kMIT1.0.3

ImageMagick binding over convert functionality

imagemagick, promise, async, convert, resize

readme

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: `shell script npm install --save imagemagick-convert


With Yarn:
```shell script
yarn add imagemagick-convert

ImageMagick installation (see more details):

OS Command
OS X brew install imagemagick
Ubuntu/Debian apt-get install imagemagick
Centos/RHEL yum install ImageMagick
Alpine apk 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:

fit fill crop
Original image Original image Original image

API reference

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

Options:

Attribute Type Required Default Description
srcData Buffer * | source image
srcFormat Dictionary | auto-detection source file format (explicit specification), for more details see ImageMagick Supported Image Formats
width Integer | source width output image width in pixels
height Integer | source height output image height in pixels
resize Enum | crop style of resizing: crop, fit, fill
density Integer | 600 density/resolution for rendering an image from vector formats such as Postscript, PDF, WMF, SVG
background String | none background color or transparency for images
gravity Dictionary | Center gravity option, for more details see ImageMagick gravity options
format Dictionary | source format output file format, for more details see ImageMagick Supported Image Formats
quality Integer | 75 JPEG/MIFF/PNG compression level: 1 - 100
blur Float | 0 blur level: 0 - 1
rotate Integer | 0 rotating degrees
flip Boolean | false vertical flip