imagemagick-native-2
v0.2.9
Published
ImageMagick's Magick++ bindings for NodeJS
Downloads
5
Readme
node-imagemagick-native
Imagemagick's Magick++ binding for Node.
Example
var imagemagick = require('imagemagick-native')
, srcData = require('fs').readFileSync('./test/test.png');
// returns a Buffer instance
var resizedBuffer = imagemagick.convert({
srcData: srcData, // provide a Buffer instance
width: 100,
height: 100,
resizeStyle: "aspectfill",
quality: 80,
format: 'JPEG'
});
require('fs').writeFileSync('./test/out.png', resizedBuffer, 'binary');
API
convert( options )
Convert a buffer provided as options.srcData
and return a Buffer.
The options
argument can have following values:
{
srcData: required. Buffer with binary image data
quality: optional. 0-100 integer, default 75. JPEG/MIFF/PNG compression level.
width: optional. px.
height: optional. px.
resizeStyle: optional. default: "aspectfill". can be "aspectfit", "fill"
aspectfill: keep aspect ratio, get the exact provided size,
crop top/bottom or left/right if necessary
aspectfit: keep aspect ratio, get maximum image that fits inside provided size
fill: forget aspect ratio, get the exact provided size
format: optional. one of http://www.imagemagick.org/script/formats.php ex: "JPEG"
rotate: optional. degrees.
debug: optional. 1 or 0
}
identify( options )
Identify a buffer provided as srcData
and return an object.
The options
argument can have following values:
{
srcData: required. Buffer with binary image data
debug: optional. 1 or 0
}
The method returns an object similar to:
{
format: 'JPEG',
width: 3904,
height: 2622,
depth: 8,
exif: {
orientation: 0 # 0 if none exists
}
}
quantizeColors( options )
Quantize the image to a specified amount of colors from a buffer provided as srcData
and return an array.
The options
argument can have following values:
{
srcData: required. Buffer with binary image data
colors: required. number of colors to extract, defaults to 5
debug: optional. 1 or 0
}
The method returns an array similar to:
[
{
r: 83,
g: 56,
b: 35,
hex: '533823'
},
{
r: 149,
g: 110,
b: 73,
hex: '956e49'
},
{
r: 165,
g: 141,
b: 111,
hex: 'a58d6f
}
]
composite( options )
Composite a buffer provided as options.compositeData
on a buffer provided as options.srcData
with gravity specified by options.gravity
and return a Buffer.
The options
argument can have following values:
{
srcData: required. Buffer with binary image data
compositeData: required. Buffer with binary image data
gravity: optional. Can be one of "CenterGravity" "EastGravity" "ForgetGravity" "NorthEastGravity" "NorthGravity" "NorthWestGravity" "SouthEastGravity" "SouthGravity" "SouthWestGravity" "WestGravity"
debug: optional. 1 or 0
}
This library currently provide only these, please try node-imagemagick if you want more.
Installation
Linux / Mac
Install Imagemagick with headers before installing this module. Tested with ImageMagick 6.7.7 on CentOS6 and MacOS10.7, Ubuntu12.04 .
MacOS10.9 Maverick users need ImageMagick linked to libstdc++ .
see issue#17
# bottle for mountain lion is linked to libstdc++
wget "http://downloads.sourceforge.net/project/machomebrew/Bottles/imagemagick-6.8.7-7.mountain_lion.bottle.tar.gz"
brew install imagemagick-6.8.7-7.mountain_lion.bottle.tar.gz
Otherwise:
brew install imagemagick
or
sudo yum install ImageMagick-c++ ImageMagick-c++-devel
or
sudo apt-get install libmagick++-dev
Make sure you can find Magick++-config in your PATH. Then:
npm install imagemagick-native
Windows
Tested on Windows 7 x64.
Install Python 2.7.3 only 2.7.3 nothing else works quite right!
If you use Cygwin ensure you don't have Python installed in Cygwin setup as there will be some confusion about what version to use.
Install Visual Studio C++ 2010 Express
(64-bit only) Install Windows 7 64-bit SDK
Install Imagemagick dll binary x86 Q16 or Imagemagick dll binary x64 Q16, check for libraries and includes during install.
Then:
npm install imagemagick-native
Performance - simple thumbnail creation
imagemagick: 16.09ms per iteration
imagemagick-native: 0.89ms per iteration
See node test/benchmark.js
for details.
License (MIT)
Copyright (c) Masakazu Ohtsuka http://maaash.jp/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.