ImageMagick binding over convert functionality
npm install imagemagick-convertNode.js wrapper for ImageMagick CLI for simple converting images.
* Node.js >= 7.10.1
* ImageMagick >= 6.9.5
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|apt-get install imagemagick
|Ubuntu/Debian||yum install ImageMagick
|Centos/RHEL||apk add --update imagemagick
|Alpine||
`javascript
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|
|---|---|---|
|!Original image|!Original image|!Original image|
convert(options: Object):Promise - 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 |