为什么node-exif库无法为某些图像显示某些标签?

时间:2019-04-03 21:49:20

标签: node.js jpeg exif

我正在尝试从图像集合中获取所有的Exif标签。查找缩放和非缩放图像。我成功地识别了图像,因为代码能够拾取某些图像的 Compression 标记,其值为 6 。但是没有从其余图像中提取任何元数据。

我需要 XResolution YResolution 来找到要在这些文件中进行的确切更改。我正在使用this库。

请在下面找到代码-

//requiring path and fs modules
const path = require('path');
const fs = require('fs');
//joining path of directory 
const directoryPath = path.join(__dirname, 'assets/images/');

var ExifImage = require('exif').ExifImage;
//passsing directoryPath and callback function
fs.readdir(directoryPath, function (err, files) {
    //handling error
    if (err) {
        return console.log('Unable to scan directory: ' + err);
    } 
    var fs = require('fs');
    var stream = fs.createWriteStream("output.txt");
    stream.once('open', function(fd) {
        //listing all files using forEach
        files.forEach(function (file) {
            // Do whatever you want to do with the file
            try {
                new ExifImage({ image : directoryPath + file }, function (error, exifData) {
                    if (error){
                        console.log('Error: '+error.message);
                    }
                    else {
                        if( exifData['thumbnail']['Compression'] == 6 ){
                            var fileString = file + '\r\n';
                            console.log('File: ' + fileString);
                            stream.write( fileString );
                        }
                    }
                });
            } catch (error) {
                console.log('Error: ' + error.message);
            }
        });
    });
}); 

请帮助。

0 个答案:

没有答案
相关问题