I am trying to use the image-size module to get the width of an image via URL. I followed their directions explicitly but can't find the "HTTP" module anywhere (which this seems to require).
I'm fairly new to node.js. Here is my code:
var url = require('/usr/lib/node_modules/url');
// var http = require('/usr/lib/node_modules/http'); *** Can't find this to download
var imgSize = require('/usr/lib/node_modules/image-size/');
var imgUrl = 'http://my.nintendo.com/static/images/common/ogp/my-nintendo.png';
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(imgSize(buffer));
});
});
Here is a link to the package on NPM: https://www.npmjs.com/package/image-size
You must require like this at the top of your file:
var url = require('url');
var http = require('http');
var sizeOf = require('image-size');
You have the module installed in your project node_modules folder?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.