Node.js wrapper for ImageMagick CLI for simple converting images.
- Node.js >= 7.10.1
- ImageMagick >= 6.9.5
With NPM:
npm install --save imagemagick-convert
With Yarn:
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 |
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:
Converted to PNG and resized:
fit | fill | crop |
---|---|---|
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 |