图片在阿里云,想通过Node获取图片的尺寸,供iOS客户端展示,怎样做到不把图片下载下来的情况下,获取图片的尺寸或比例?
巴扎黑2017-04-17 12:06:30
Found the solution.
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));
});
});
Image-size is a third-party library for obtaining image size. With the http module, the image size can be obtained remotely.