ImageMagic module for NodeJS
Tested with
- Linux x64
- Windows x86 / Visual Studio 2015
- ImageMagic 6.9.6
- NodeJS 6.7.0
Installation
- Install ImageMagic 6.9.6
- Windows only configure IMAGEMAGICK_HOME environment variable to root of ImageMagic installation (e.g. C:\Program Files (x86)\ImageMagick-6.9.6-Q16-HDRI )
- Windows only If you have problems with ssize_t during build comment line #246 in %IMAGEMAGICK_HOME%\include\magick\magick-baseconfig.h (typedef int ssize_t) TODO: Solve this issue in better way
- npm install imagemagic2
- electorn only You may need to rebuild library for specific node version user in electron
Usage
Basic Example
To use imagemagick first you need to create and image, currently only reading from file is supported.
const image = ; var img = ;
Than you can apply transformations and/or calculations on image with fluent style. Note than transformations/calculations and even reading image from file will be performed only after apply() method is called.
const image = ; // Do nothing just save action // Do nothing just save action // Do nothing just save action ; //Apply all actions
Apply returns promise.
const image = ; ;
To handle results of every action you can use action callback. In case of any error action callback will not be called and global promise will fail;
const image = ; ;
Additionally you can perform any custom action after any operation with method do.
const image = ; ;
Apply time actions
In some cases you may need to decide to continue some transformations or not based on results of previous transformations/calculations. In that case you can use apply time actions.
const image = ; size { ifsizewidth > 640 img ; } ;
Methods
Resize
const image = ; ;
Rotate
const image = ; ;
Write
const image = ; ;
Grayscale
const image = ; ;
Strip (remove all additional data like EXIF or thumbnails)
const image = ; ;
Size (retrieves image size)
const image = ; size { console };
Brightness histogram
const image = ; ;