Skip to content

Instantly share code, notes, and snippets.

@akshay-bhardwaj
Last active August 29, 2015 14:17
Show Gist options
  • Save akshay-bhardwaj/e797e8c326a908c404a0 to your computer and use it in GitHub Desktop.
Save akshay-bhardwaj/e797e8c326a908c404a0 to your computer and use it in GitHub Desktop.
var fs = require('fs'),
request = require('request'),
sizeOf = require('image-size');
var url = "http://www.dailytechtuts.com/wp-content/uploads/cute-white-rat.jpg";
var file_path = '/tmp/google.png'
var download = function(uri, filename, callback){
request.head(uri, function(err, res, body){
console.log('content-type:', res.headers['content-type']);
console.log('content-length:', res.headers['content-length']);
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
});
};
download(url, file_path, function(){
console.log('done');
sizeOf(file_path, function (err, dimensions) {
console.log(dimensions.width, dimensions.height);
fs.unlink(file_path);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment