Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 184 lines (137 sloc) 5.304 kb
4cbe8cd @rsms it's alive
authored
1 # node-imagemagick
2
8ad6a7f @rsms Update README.md
authored
3 **This is an abandoned version. Please see [@yourdeveloper/node-imagemagick](https://github.com/yourdeveloper/node-imagemagick) for the currently maintained version**
bd4193e @rsms Update README.md
authored
4
4cbe8cd @rsms it's alive
authored
5 [Imagemagick](http://www.imagemagick.org/) module for [Node](http://nodejs.org/).
6
bd4193e @rsms Update README.md
authored
7 > Note: This code has been unmaintained for a long time. Please consider using the [gm](https://github.com/aheckmann/gm) module instead.
f88f4eb @rsms Update README.md
authored
8
33dc61b @rsms npm installation note
authored
9 You can install this module using [npm](http://github.com/isaacs/npm):
10
11 npm install imagemagick
12
34c8deb @rsms Got rid of long gone sys module dependency as well as adding test matter...
authored
13 Requires imagemagick CLI tools to be installed. There are numerous ways to install them. For instance, if you're on OS X you can use [Homebrew](http://mxcl.github.com/homebrew/): `brew install imagemagick`.
14
4cbe8cd @rsms it's alive
authored
15 ## Example
16
751aca9 @rsms [readme] js code blocks use gh-style markup to enable syntax highlightin...
authored
17 ```javascript
18 var im = require('imagemagick');
19 im.readMetadata('kittens.jpg', function(err, metadata){
20 if (err) throw err;
21 console.log('Shot at '+metadata.exif.dateTimeOriginal);
22 })
23 // -> Shot at Tue, 06 Feb 2007 21:13:54 GMT
24 ```
4cbe8cd @rsms it's alive
authored
25
26 ## API
27
28 ### convert.path
29
30 Path to the `convert` program. Defaults to `"convert"`.
31
32 ### identify.path
33
34 Path to the `identify` program. Defaults to `"identify"`.
35
36 ### identify(path, callback(err, features))
37
38 Identify file at `path` and return an object `features`.
39
40 Example:
41
751aca9 @rsms [readme] js code blocks use gh-style markup to enable syntax highlightin...
authored
42 ```javascript
43 im.identify('kittens.jpg', function(err, features){
44 if (err) throw err;
45 console.log(features);
46 // { format: 'JPEG', width: 3904, height: 2622, depth: 8 }
47 });
48 ```
4cbe8cd @rsms it's alive
authored
49
50 ### identify(args, callback(err, output))
51
52 Custom identification where `args` is an array of arguments. The result is returned as a raw string to `output`.
53
54 Example:
55
751aca9 @rsms [readme] js code blocks use gh-style markup to enable syntax highlightin...
authored
56 ```javascript
57 im.identify(['-format', '%wx%h', 'kittens.jpg'], function(err, output){
58 if (err) throw err;
59 console.log('dimension: '+output);
60 // dimension: 3904x2622
61 });
62 ```
4cbe8cd @rsms it's alive
authored
63
64 ### readMetadata(path, callback(err, metadata))
65
66 Read metadata (i.e. exif) in `path` and return an object `metadata`. Modelled on top of `identify`.
67
68 Example:
69
751aca9 @rsms [readme] js code blocks use gh-style markup to enable syntax highlightin...
authored
70 ```javascript
71 im.readMetadata('kittens.jpg', function(err, metadata){
72 if (err) throw err;
73 console.log('Shot at '+metadata.exif.dateTimeOriginal);
74 // -> Shot at Tue, 06 Feb 2007 21:13:54 GMT
75 });
76 ```
4cbe8cd @rsms it's alive
authored
77
78 ### convert(args, callback(err, stdout, stderr))
79
80 Raw interface to `convert` passing arguments in the array `args`.
81
82 Example:
83
751aca9 @rsms [readme] js code blocks use gh-style markup to enable syntax highlightin...
authored
84 ```javascript
85 im.convert(['kittens.jpg', '-resize', '25x120', 'kittens-small.jpg'],
cba60ba @rsms [readme] Fixed typo in code example
authored
86 function(err, stdout){
751aca9 @rsms [readme] js code blocks use gh-style markup to enable syntax highlightin...
authored
87 if (err) throw err;
88 console.log('stdout:', stdout);
89 });
90 ```
4cbe8cd @rsms it's alive
authored
91
92 ### resize(options, callback(err, stdout, stderr))
93
94 Convenience function for resizing an image, modelled on top of `convert`.
95
96 The `options` argument have the following default values:
97
751aca9 @rsms [readme] js code blocks use gh-style markup to enable syntax highlightin...
authored
98 ```javascript
99 {
100 srcPath: undefined,
101 srcData: null,
102 srcFormat: null,
103 dstPath: undefined,
104 quality: 0.8,
105 format: 'jpg',
106 progressive: false,
107 width: 0,
108 height: 0,
109 strip: true,
110 filter: 'Lagrange',
111 sharpening: 0.2,
112 customArgs: []
113 }
114 ```
4cbe8cd @rsms it's alive
authored
115
116 srcPath, dstPath and (at least one of) width and height are required. The rest is optional.
117
118 Example:
119
751aca9 @rsms [readme] js code blocks use gh-style markup to enable syntax highlightin...
authored
120 ```javascript
121 im.resize({
122 srcPath: 'kittens.jpg',
123 dstPath: 'kittens-small.jpg',
124 width: 256
125 }, function(err, stdout, stderr){
126 if (err) throw err;
127 console.log('resized kittens.jpg to fit within 256x256px');
128 });
129 ```
4cbe8cd @rsms it's alive
authored
130
d5c942e @rsms added support for pipe I/O
authored
131 Example with stdin/stdout:
132
751aca9 @rsms [readme] js code blocks use gh-style markup to enable syntax highlightin...
authored
133 ```javascript
134 var fs = require('fs');
135 im.resize({
136 srcData: fs.readFileSync('kittens.jpg', 'binary'),
137 width: 256
138 }, function(err, stdout, stderr){
139 if (err) throw err
140 fs.writeFileSync('kittens-resized.jpg', stdout, 'binary');
141 console.log('resized kittens.jpg to fit within 256x256px')
142 });
143 ```
d5c942e @rsms added support for pipe I/O
authored
144
9f04c8f @sdepold added crop to readme
sdepold authored
145 ### crop(options, callback) ###
c27f797 @pbrumm Enabling gravity to be specified as an option
pbrumm authored
146 Convenience function for resizing and cropping an image. _crop_ uses the resize method, so _options_ and _callback_ are the same. _crop_ uses _options.srcPath_, so make sure you set it :) Using only _options.width_ or _options.height_ will create a square dimensioned image. Gravity can also be specified, it defaults to Center. Available gravity options are [NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast]
9f04c8f @sdepold added crop to readme
sdepold authored
147
148 Example:
149
751aca9 @rsms [readme] js code blocks use gh-style markup to enable syntax highlightin...
authored
150 ```javascript
151 im.crop({
152 srcPath: path,
153 dstPath: 'cropped.jpg',
154 width: 800,
155 height: 600,
156 quality: 1,
157 gravity: "North"
158 }, function(err, stdout, stderr){
159 // foo
160 });
161 ```
9f04c8f @sdepold added crop to readme
sdepold authored
162
4cbe8cd @rsms it's alive
authored
163 ## License (MIT)
164
34c8deb @rsms Got rid of long gone sys module dependency as well as adding test matter...
authored
165 Copyright (c) 2010-2012 Rasmus Andersson <http://hunch.se/>
4cbe8cd @rsms it's alive
authored
166
167 Permission is hereby granted, free of charge, to any person obtaining a copy
168 of this software and associated documentation files (the "Software"), to deal
169 in the Software without restriction, including without limitation the rights
170 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
171 copies of the Software, and to permit persons to whom the Software is
172 furnished to do so, subject to the following conditions:
173
174 The above copyright notice and this permission notice shall be included in
175 all copies or substantial portions of the Software.
176
177 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
178 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
179 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
180 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
181 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
182 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
183 THE SOFTWARE.
Something went wrong with that request. Please try again.