Skip to content

Commit 90de79c

Browse files
author
Shogun
committed
Added support for local files and documentation.
1 parent 006b20b commit 90de79c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+13755
-75
lines changed

.jshintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"curly": false
3+
}

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
#
2+
# This file is part of the fastimage node module. Copyright (C) 2015 and above Shogun <shogun@cowtech.it>.
3+
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
4+
#
5+
16
language: node_js
7+
script: npm run-script travis-ci
28
node_js:
39
- "0.12"
410
- "0.11"

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2+
### 2015-03-14 / 0.2.0 - The PI release!
3+
4+
* Added support for analyzing local files.
5+
* Added `realPath`, `realUrl` and `size` to the returned objects.
6+
* Added documentation.
7+
* Improved README.
8+
19
### 2015-03-10 / 0.1.1
210

311
* Export `FastImageError` as well.

README.md

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,115 @@ FastImage finds the size or type of an image given its URL by fetching as little
1010

1111
http://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

19.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)