1 | # node-imaginary [![Build Status](https://api.travis-ci.org/h2non/node-imaginary.svg?branch=master)][travis] [![Dependency Status](https://gemnasium.com/h2non/node-imaginary.svg)][gemnasium] [![NPM version](https://badge.fury.io/js/imaginary.svg)][npm]
|
2 |
|
3 | Minimalist node.js/io.js CLI & programmatic stream capable interface for [imaginary](https://github.com/h2non/imaginary) server.
|
4 |
|
5 | Supports multiple image operations such as resize, crop, zoom, watermark, rotate... and both local and remote URL based image source processing, and additionally provides a simple balancing feature to use multiple imaginary servers.
|
6 |
|
7 | To get started take a look to the [command-line usage](#cli) and programmatic [API](#api)
|
8 |
|
9 | ## Installation
|
10 |
|
11 | For command-line usage, install it as global package:
|
12 | ```bash
|
13 | npm install -g imaginary
|
14 | ```
|
15 |
|
16 | For programmatic usage, install it in the tree dependency:
|
17 | ```bash
|
18 | npm install imaginary --save[-dev]
|
19 | ```
|
20 |
|
21 | ## CLI
|
22 |
|
23 | ```bash
|
24 | $ imaginary --help
|
25 | ```
|
26 |
|
27 | ```bash
|
28 | Usage: imaginary [options] [command]
|
29 |
|
30 | Commands:
|
31 |
|
32 | crop [options] [image] Crop any image to a given square thumbnail in pixels
|
33 | resize [options] [image] Resize the image to the given width or height in pixels
|
34 | embed [options] [image] Embed the image to the given width or height in pixels
|
35 | extract [options] [image] Extract area from an image by top/left and width/height
|
36 | enlarge [options] [image] Enlarge the image to the given width and height in pixels
|
37 | rotate [options] [image] Rotate the image by degrees
|
38 | flip [options] [image] Flip an image
|
39 | flop [options] [image] Flop an image
|
40 | zoom [options] [image] Zoom the image to the given width or height in pixels
|
41 | watermark [options] [image] Add a text watermark in the image
|
42 | info [options] [image] Retrieve image information as JSON
|
43 |
|
44 | Options:
|
45 |
|
46 | -h, --help output usage information
|
47 | -V, --version output the version number
|
48 |
|
49 | Examples:
|
50 |
|
51 | $ imaginary crop -w 200 -o out.jpg image.jpg
|
52 | $ imaginary resize -w 300 -o out.jpg http://server.net/image.jpg
|
53 | $ imaginary zoom -f 2 -w 300 -o out.jpg http://server.net/image.jpg
|
54 | $ imaginary watermark --text "copyright" -o out.jpg http://server.net/image.jpg
|
55 | ```
|
56 |
|
57 | ## API
|
58 |
|
59 | ### imaginary(image, [imaginaryUrl])
|
60 |
|
61 | Constructor of the imaginary client
|
62 |
|
63 | Take an image from disk:
|
64 | ```js
|
65 | var fs = require('fs')
|
66 | var imaginary = require('imaginary')
|
67 | var serverUrl = 'http://imaginary.company.net'
|
68 |
|
69 | imaginary('image.jpg')
|
70 | .server(serverUrl)
|
71 | .crop({ widht: 200 })
|
72 | .on('error', function (err) {
|
73 | console.error('Cannot resize the image:', err)
|
74 | })
|
75 | .pipe(fs.createWriteStream('out.jpg'))
|
76 | ```
|
77 |
|
78 | Take an image from remote URL:
|
79 | ```js
|
80 | imaginary('http://server.com/image.jpg')
|
81 | .crop({ width: 100 })
|
82 | .on('error', function (err) {
|
83 | console.error('Cannot resize the image:', err)
|
84 | })
|
85 | .pipe(fs.createWriteStream('out.jpg'))
|
86 | ```
|
87 |
|
88 | Take an image as readable stream:
|
89 | ```js
|
90 | imaginary(fs.readFileStream('image.jpg'))
|
91 | .crop({ width: 100 })
|
92 | .on('error', function (err) {
|
93 | console.error('Cannot resize the image:', err)
|
94 | })
|
95 | .pipe(fs.createWriteStream('out.jpg'))
|
96 | ```
|
97 |
|
98 | ### Supported params
|
99 |
|
100 | See the full list of supported query params [here](https://github.com/h2non/imaginary#params).
|
101 |
|
102 | Take a look to each specific endpoint to see which specific params are supported or not.
|
103 | Image measures are always in pixels, unless otherwise indicated.
|
104 |
|
105 | #### imaginary#key(key)
|
106 |
|
107 | Define the API key required by the imaginary server (optional)
|
108 |
|
109 | #### imaginary#server(url)
|
110 |
|
111 | Define the imaginary server URL
|
112 |
|
113 | #### imaginary#balance(urls)
|
114 |
|
115 | Define a pool of imaginary servers to balance load across them.
|
116 |
|
117 | #### imaginary#image(image)
|
118 |
|
119 | Pass the image path, image URL or `ReadableStream` to the image file
|
120 |
|
121 | #### imaginary#imageUrl(url)
|
122 |
|
123 | Pass the image URL to process
|
124 |
|
125 | Balance between a pool of imaginary server URLs
|
126 |
|
127 | #### imaginary#params(params, [ callback ])
|
128 |
|
129 | #### imaginary#crop(params, [ callback ])
|
130 |
|
131 | Crop an image to a given square thumbnail in pixels.
|
132 |
|
133 | #### imaginary#resize(params, [ callback ])
|
134 |
|
135 | Resize an image by width, height or both
|
136 |
|
137 | #### imaginary#enlarge(params, [ callback ])
|
138 |
|
139 | Enlarge an image by width and/or height
|
140 |
|
141 | #### imaginary#extract(params, [ callback ])
|
142 |
|
143 | Extract image area by top/left and width/height pixels
|
144 |
|
145 | #### imaginary#expand(params, [ callback ])
|
146 |
|
147 | Resize any image to a given height in pixels.
|
148 |
|
149 | #### imaginary#zoom(params, [ callback ])
|
150 |
|
151 | Zoom an image by the given height in pixels.
|
152 |
|
153 | #### imaginary#rotate(params, [ callback ])
|
154 |
|
155 | Rotate an image to a given degrees (must be multiple of 90)
|
156 |
|
157 | #### imaginary#flip(params, [ callback ])
|
158 |
|
159 | Flip an image
|
160 |
|
161 | #### imaginary#flop(params, [ callback ])
|
162 |
|
163 | Flop an image
|
164 |
|
165 | #### imaginary#watermark(params, [ callback ])
|
166 |
|
167 | Add a watermark to an image
|
168 |
|
169 | #### imaginary#thumbnail(params, [ callback ])
|
170 |
|
171 | Thumbnail an image with a given width or height
|
172 |
|
173 | #### imaginary#info([ callback ])
|
174 |
|
175 | Get the metadata info of the image as JSON
|
176 |
|
177 | #### imaginary#health([ callback ])
|
178 |
|
179 | Retrieve server health status
|
180 |
|
181 | #### imaginary#versions([ callback ])
|
182 |
|
183 | Retrieve imaginary, bimg and libvips versions
|
184 |
|
185 | ### imaginary.VERSION
|
186 |
|
187 | Get the current module version
|
188 |
|
189 | ## License
|
190 |
|
191 | [MIT](http://opensource.org/licenses/MIT) © Tomas Aparicio
|
192 |
|
193 | [travis]: http://travis-ci.org/h2non/node-imaginary
|
194 | [gemnasium]: https://gemnasium.com/h2non/node-imaginary
|
195 | [npm]: http://npmjs.org/package/imaginary
|