UNPKG

5.33 kBMarkdownView Raw
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
3Minimalist node.js/io.js CLI & programmatic stream capable interface for [imaginary](https://github.com/h2non/imaginary) server.
4
5Supports 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
7To get started take a look to the [command-line usage](#cli) and programmatic [API](#api)
8
9## Installation
10
11For command-line usage, install it as global package:
12```bash
13npm install -g imaginary
14```
15
16For programmatic usage, install it in the tree dependency:
17```bash
18npm install imaginary --save[-dev]
19```
20
21## CLI
22
23```bash
24$ imaginary --help
25```
26
27```bash
28Usage: imaginary [options] [command]
29
30Commands:
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
44Options:
45
46 -h, --help output usage information
47 -V, --version output the version number
48
49Examples:
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
61Constructor of the imaginary client
62
63Take an image from disk:
64```js
65var fs = require('fs')
66var imaginary = require('imaginary')
67var serverUrl = 'http://imaginary.company.net'
68
69imaginary('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
78Take an image from remote URL:
79```js
80imaginary('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
88Take an image as readable stream:
89```js
90imaginary(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
100See the full list of supported query params [here](https://github.com/h2non/imaginary#params).
101
102Take a look to each specific endpoint to see which specific params are supported or not.
103Image measures are always in pixels, unless otherwise indicated.
104
105#### imaginary#key(key)
106
107Define the API key required by the imaginary server (optional)
108
109#### imaginary#server(url)
110
111Define the imaginary server URL
112
113#### imaginary#balance(urls)
114
115Define a pool of imaginary servers to balance load across them.
116
117#### imaginary#image(image)
118
119Pass the image path, image URL or `ReadableStream` to the image file
120
121#### imaginary#imageUrl(url)
122
123Pass the image URL to process
124
125Balance between a pool of imaginary server URLs
126
127#### imaginary#params(params, [ callback ])
128
129#### imaginary#crop(params, [ callback ])
130
131Crop an image to a given square thumbnail in pixels.
132
133#### imaginary#resize(params, [ callback ])
134
135Resize an image by width, height or both
136
137#### imaginary#enlarge(params, [ callback ])
138
139Enlarge an image by width and/or height
140
141#### imaginary#extract(params, [ callback ])
142
143Extract image area by top/left and width/height pixels
144
145#### imaginary#expand(params, [ callback ])
146
147Resize any image to a given height in pixels.
148
149#### imaginary#zoom(params, [ callback ])
150
151Zoom an image by the given height in pixels.
152
153#### imaginary#rotate(params, [ callback ])
154
155Rotate an image to a given degrees (must be multiple of 90)
156
157#### imaginary#flip(params, [ callback ])
158
159Flip an image
160
161#### imaginary#flop(params, [ callback ])
162
163Flop an image
164
165#### imaginary#watermark(params, [ callback ])
166
167Add a watermark to an image
168
169#### imaginary#thumbnail(params, [ callback ])
170
171Thumbnail an image with a given width or height
172
173#### imaginary#info([ callback ])
174
175Get the metadata info of the image as JSON
176
177#### imaginary#health([ callback ])
178
179Retrieve server health status
180
181#### imaginary#versions([ callback ])
182
183Retrieve imaginary, bimg and libvips versions
184
185### imaginary.VERSION
186
187Get 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