使用node-canvas获取GIF的文件大小?

时间:2013-10-30 01:57:49

标签: node.js node-canvas

经过多次努力,我设法在Windows上安装了node-canvas

但是,当我尝试读取GIF的图像尺寸时,它只会让我的宽度和高度为0。

var FileSystem = require('fs');
var Canvas = require('canvas');

FileSystem.readdir(baseDir, function(err, files) {
    files.forEach(function(filename) {
        var path = Path.join(baseDir, filename);
        FileSystem.readFile(path, function(err, buf) {
            var img = new Canvas.Image;
            img.src = buf;
            console.log(path, img.width, img.height);
        });
});

它不应该能够阅读GIF吗?

1 个答案:

答案 0 :(得分:1)

您必须安装giflib并重新安装node-canvas,就像在https://github.com/LearnBoost/node-canvas/wiki/Installation---OSX中所说的那样,然后您就可以操作您的gif文件(检索宽度/高度)。但请注意,使用画布处理的图像将停止动画。