You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For the details about the second parameter of the callback, see [fastimage.analyze](#user-content-fastimageanalyzeurl-callback),
42
-
[fastimage.size](#user-content-fastimagesizeurl-callback) and [fastimage.type](#user-content-fastimagetypeurl-callback).
43
+
For the details about the second parameter of the callback, see [fastimage.info](#user-content-fastimageinfosubject-callback),
44
+
[fastimage.size](#user-content-fastimagesizesubject-callback) and [fastimage.type](#user-content-fastimagetypesubject-callback).
43
45
44
46
### Promise style
45
47
46
-
# TODO
48
+
All the fastime image methods `info`, `filteredInfo`, `size` and `type` return a Promise. Once resolved, the promises have the same payload of the callbacks.
49
+
50
+
```javascript
51
+
var fastimage =require("fastimage");
52
+
53
+
fastimage.info("http://placehold.it/100x100")
54
+
.then(function(info){
55
+
// ...
56
+
})
57
+
.catch(function(error){
58
+
// ...
59
+
});
60
+
```
47
61
48
62
### Stream style
49
63
50
-
# TODO
64
+
If you want to go *The Node.js Way*, you can use the streaming API.
65
+
66
+
Calling `fastimage.stream` it will return a Duplex stream object. Called without arguments, it's ideal for piping. Otherwise, you can use only it's readable side.
Copy file name to clipboardExpand all lines: docs/index.html
+58-10Lines changed: 58 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -61,18 +61,35 @@ <h3> </h3>
61
61
<li>WebP</li>
62
62
<li>SVG</li>
63
63
</ul>
64
-
<h2>Usage</h2><h3>Callback style</h3><p>To get the image informations, call <code>fastimage.analyze</code> passing the URL (can be also a local file path) and a callback.</p>
64
+
<h2>Usage</h2><p>For more details usage examples, see the <code>examples</code> folder.</p>
65
+
<h3>Callback style</h3><p>To get the image informations, call <code>fastimage.info</code> passing the URL (can be also a local file path or a Buffer) and a callback.</p>
});</code></pre><p>For the details about the second parameter of the callback, see <ahref="#user-content-fastimageanalyzeurl-callback">fastimage.analyze</a>,
73
-
<ahref="#user-content-fastimagesizeurl-callback">fastimage.size</a> and <ahref="#user-content-fastimagetypeurl-callback">fastimage.type</a>.</p>
74
-
<h3>Promise style</h3><h1>TODO</h1><h3>Stream style</h3><h1>TODO</h1><h2>Supported implementations.</h2><p>Chalkbars supports and has been tested on <ahref="http://nodejs.org">NodeJS</a> 0.10+ and <ahref="http://iojs.org">io.js</a> 1.0+.</p>
75
-
<h2>API Documentation</h2><h3>fastimage.analyze(url, callback)</h3><p>Analyzes a URL (local or remote) and return the image informations.</p>
73
+
});</code></pre><p>For the details about the second parameter of the callback, see <ahref="#user-content-fastimageinfosubject-callback">fastimage.info</a>,
74
+
<ahref="#user-content-fastimagesizesubject-callback">fastimage.size</a> and <ahref="#user-content-fastimagetypesubject-callback">fastimage.type</a>.</p>
75
+
<h3>Promise style</h3><p>All the fastime image methods <code>info</code>, <code>filteredInfo</code>, <code>size</code> and <code>type</code> return a Promise. Once resolved, the promises have the same payload of the callbacks.</p>
});</code></pre><h3>Stream style</h3><p>If you want to go <em>The Node.js Way</em>, you can use the streaming API.</p>
85
+
<p>Calling <code>fastimage.stream</code> it will return a Duplex stream object. Called without arguments, it's ideal for piping. Otherwise, you can use only it's readable side.</p>
fastimage.stream("http://placehold.it/100x100.png").pipe(/*...*/);</code></pre><p>Streams will emit the <code>size</code> and <code>type</code> if you only need those informations.</p>
91
+
<h2>Supported implementations.</h2><p>Fastimage supports and has been tested on <ahref="http://nodejs.org">NodeJS</a> 0.10+ and <ahref="http://iojs.org">io.js</a> 1.0+.</p>
92
+
<h2>API Documentation</h2><h3>fastimage.info(subject, [callback])</h3><p>Analyzes a URL (local or remote) or a Buffer and return the image informations.</p>
76
93
<p>The signature of the callback is <code>function(error, info)</code>.</p>
77
94
<p>The first argument of the callback, when failed, will be a <ahref="#user-content-fastimageFastImageError">FastImageError</a> instance.</p>
78
95
<p>The second argument of the callback, when successful, will be a object containing the image informations.</p>
@@ -95,14 +112,45 @@ <h2>API Documentation</h2><h3>fastimage.analyze(url, callback)</h3><p>Analyzes a
95
112
"realPath": "/home/user/1.png", // The absolute path of the image. It will be omitted if equals to the path.
96
113
"size": 24090, // The size (in bytes) of the image.
97
114
"time": 14.00558 // The time required for the operation, in milliseconds.
98
-
}</code></pre><h3>fastimage.size(url, callback)</h3><p>Analyzes a URL (local or remote) and return the image size.</p>
115
+
}</code></pre><p>When the source is a Buffer the object will be similar to this:</p>
"width": 150, // The width of the image in pixels.
118
+
"height": 150, // The height of the image in pixels.
119
+
"type": "png", // The type of the image. Can be `bmp`, `gif`, `jpeg`, `png`, `psd`, `tif`, `webp` or `svg`.
120
+
"analyzed": 4096 // The number of bytes analyzed.
121
+
"time": 14.00558 // The time required for the operation, in milliseconds.
122
+
}</code></pre><p>The function will return a Promise, which will resolve providing the information object.</p>
123
+
<h3>fastimage.size(subject, [callback])</h3><p>Analyzes a URL (local or remote) or a Buffer and return the image size.</p>
99
124
<p>The signature of the callback is <code>function(error, dimensions)</code>.</p>
100
125
<p>The first argument of the callback, when failed, will be a <ahref="#user-content-fastimageFastImageError">FastImageError</a> instance.</p>
101
126
<p>The second argument of the callback, when successful, will be a object containing the fields <code>width</code> and <code>height</code> in pixels.</p>
102
-
<h3>fastimage.type(url, callback)</h3><p>Analyzes a URL (local or remote) and return the image type.</p>
127
+
<p>The function will return a Promise, which will resolve providing the information object.</p>
128
+
<h3>fastimage.type(subject, [callback])</h3><p>Analyzes a URL (local or remote) or a Buffer and return the image type.</p>
103
129
<p>The signature of the callback is <code>function(error, type)</code>.</p>
104
130
<p>The first argument of the callback, when failed, will be a <ahref="#user-content-fastimageFastImageError">FastImageError</a> instance.</p>
105
131
<p>The second argument of the callback, when successful, will be the type of the image.</p>
132
+
<p>The function will return a Promise, which will resolve providing the image type.</p>
133
+
<h3>fastimage.filteredInfo(subject, [filter, callback])</h3><p>Analyzes a URL (local or remote) or a Buffer and return the image informations passing through a filter function.</p>
134
+
<p>The filter function should accept an object as input and return the object to be passed to the callback.</p>
135
+
<p>For details on the input object of the filter, see <ahref="#user-content-fastimageinfosubject-callback">fastimage.info</a>.</p>
136
+
<p>The signature of the callback is <code>function(error, info)</code>.</p>
137
+
<p>The first argument of the callback, when failed, will be a <ahref="#user-content-fastimageFastImageError">FastImageError</a> instance.</p>
138
+
<p>The second argument of the callback, when successful, will be a object containing the image informations.</p>
139
+
<p>The function will return a Promise, which will resolve providing the filtered information object.</p>
140
+
<h3>fastimage.stream(subject, [options])</h3><p>Creates a new fastimage stream analysis. This is a Duplex stream which works in object mode on the readable side.</p>
141
+
<p>It will emit the following events:</p>
142
+
<ul>
143
+
<li><strong>size</strong>: The payload will be a object containing the fields <code>width</code> and <code>height</code> in pixels.</li>
144
+
<li><strong>type</strong>: The payload will the type of the image.</li>
145
+
</ul>
146
+
<h3>fastimage.timeout([timeout])</h3><p>Gets or sets the maximum number of seconds to wait to connect to a host.</p>
147
+
<p>If the value is present, it will also set the new value. If the value is <code>null</code>, it will restore the default value.</p>
148
+
<p>The default value is <code>30000</code>.</p>
149
+
<h3>fastimage.threshold([threshold])</h3><p>Gets or sets the maximum number of bytes to read to attempt an identification before giving up and state that the source is not an image.</p>
150
+
<p>If the value is present, it will also set the new value. If the value is <code>null</code>, it will restore the default value.</p>
0 commit comments