@@ -10,13 +10,115 @@ FastImage finds the size or type of an image given its URL by fetching as little
1010
1111http://sw.cowtech.it/fastimage
1212
13+ The supported image type are (thanks to the [ image-size] ( https://github.com/netroy/image-size ) module):
14+
15+ * BMP
16+ * GIF
17+ * JPEG
18+ * PNG
19+ * PSD
20+ * TIFF
21+ * WebP
22+ * SVG
23+
1324## Usage
1425
15- TODO
26+ ### Callback style
27+
28+ To get the image informations, call ` fastimage.analyze ` passing the URL (can be also a local file path) and a callback.
29+
30+ ``` javascript
31+ var fastimage = require (" fastimage" );
32+ fastimage .analyze (" http://placehold.it/100x100" , function (error , information ){
33+ if (error){
34+ // ...
35+ else {
36+ // ...
37+ }
38+ });
39+ ` ` `
40+
41+ 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+
44+ ### Promise style
45+
46+ # TODO
47+
48+ ### Stream style
49+
50+ # TODO
1651
1752## Supported implementations.
1853
19- TODO
54+ Chalkbars supports and has been tested on [NodeJS](http://nodejs.org) 0.10+ and [io.js](http://iojs.org) 1.0+.
55+
56+ ## API Documentation
57+
58+ ### fastimage.analyze(url, callback)
59+
60+ Analyzes a URL (local or remote) and return the image informations.
61+
62+ The signature of the callback is ` function (error , info )`.
63+
64+ The first argument of the callback, when failed, will be a [FastImageError](#user-content-fastimageFastImageError) instance.
65+
66+ The second argument of the callback, when successful, will be a object containing the image informations.
67+
68+ Specifically, when the URL is a remote URL, the object will be similar to this:
69+
70+ ```javascript
71+ {
72+ " width" : 1000 , // The width of the image in pixels.
73+ " height" : 1000 , // The height of the image in pixels.
74+ " type" : " gif" , // The type of the image. Can be `bmp`, `gif`, `jpeg`, `png`, `psd`, `tif`, `webp` or `svg`.
75+ " url" : " http://placehold.it/1000x1000.gif" , // The original URL of the image.
76+ " realUrl" : " http://placehold.it/1000x1000.gif" , // The real URL of the image after all the redirects. It will be omitted if equals to the URL.
77+ " size" : 24090 , // The size of the image (in bytes). Present only if the server returned the Content-Length HTTP header.
78+ " transferred" : 979 , // The amount of data transferred (in bytes) to identify the image.
79+ " time" : 171.43721 // The time required for the operation, in milliseconds.
80+ }
81+ ` ` `
82+
83+ When the URL is a local file the object will be similar to this:
84+
85+ ` ` ` javascript
86+ {
87+ " width" : 150 , // The width of the image in pixels.
88+ " height" : 150 , // The height of the image in pixels.
89+ " type" : " png" , // The type of the image. Can be `bmp`, `gif`, `jpeg`, `png`, `psd`, `tif`, `webp` or `svg`.
90+ " path" : " 1.png" , // The original path of the image.
91+ " realPath" : " /home/user/1.png" , // The absolute path of the image. It will be omitted if equals to the path.
92+ " size" : 24090 , // The size (in bytes) of the image.
93+ " time" : 14.00558 // The time required for the operation, in milliseconds.
94+ }
95+ ` ` `
96+
97+ ### fastimage.size(url, callback)
98+
99+ Analyzes a URL (local or remote) and return the image size.
100+
101+ The signature of the callback is ` function (error , dimensions )`.
102+
103+ The first argument of the callback, when failed, will be a [FastImageError](#user-content-fastimageFastImageError) instance.
104+
105+ The second argument of the callback, when successful, will be a object containing the fields `width` and `height` in pixels.
106+
107+ ### fastimage.type(url, callback)
108+
109+ Analyzes a URL (local or remote) and return the image type.
110+
111+ The signature of the callback is `function(error, type)`.
112+
113+ The first argument of the callback, when failed, will be a [FastImageError](#user-content-fastimageFastImageError) instance.
114+
115+ The second argument of the callback, when successful, will be the type of the image.
116+
117+ ### fastimage.FastImageError
118+
119+ This error will be returned as the first argument of the callbacks if anything goes wrong.
120+
121+ It always have the `message` and `code` fields set.
20122
21123## Contributing to fastimage
22124
0 commit comments