Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added sample code for using urls

  • Loading branch information...
commit a2bc4277f07233c7f7ec257f7550971fe5f4f936 1 parent 4d0fc63
@netroy authored
Showing with 23 additions and 0 deletions.
  1. +23 −0 Readme.md
View
23 Readme.md
@@ -22,6 +22,29 @@ sizeOf('images/funny-cats.png', function (err, dimensions) {
});
```
+##### Using a url
+```javascript
+var url = require('url');
+var http = require('http');
+
+var sizeOf = require('image-size');
+
+var imgUrl = 'http://my-amazing-website.com/image.jpeg';
+var options = url.parse(imgUrl);
+
+http.get(options, function (response) {
+ var chunks = [];
+ response.on('data', function (chunk) {
+ chunks.push(chunk);
+ }).on('end', function() {
+ var buffer = Buffer.concat(chunks);
+ console.log(sizeOf(buffer));
+ });
+});
+```
+You can optionally check the buffer lengths & stop downloading the image after a few kilobytes.
+** You don't need to download the entire image **
+
#### Supported formats
* BMP
* GIF
Please sign in to comment.
Something went wrong with that request. Please try again.