美文网首页
tinify本地压缩图片

tinify本地压缩图片

作者: 清霆 | 来源:发表于2021-11-03 13:30 被阅读0次
    const tinify = require('tinify');
    
    tinify.key = 'AAAAAAAAAA';
    
    
    
    var path = require('path');
    var fs = require('fs');
    
    var pathName = './source';
    fs.readdir(pathName, function (err, files) {
        var dirs = [];
        (function iterator (i) {
            if (i == files.length) {
                console.log(dirs);
                return;
            }
            fs.stat(path.join(pathName, files[i]), function (err, data) {
                if (data.isFile()) {
                    try {
                        dirs.push(files[i]);
                        console.log('S---------------------' + files[i] + '---------------------S')
                        const source = tinify.fromFile('./source/' + files[i]);
                        source.toFile('./target/' + files[i]);
                        console.log('E---------------------' + files[i] + '---------------------E')
                    } catch (e) {
                        console.log('EEE---------------------' + files[i] + '---------------------EEE')
                    }
                }
                iterator(i + 1);
            });
        })(0);
        console.log(dirs);
    });
    

    相关文章

      网友评论

          本文标题:tinify本地压缩图片

          本文链接:https://www.haomeiwen.com/subject/qfgqzltx.html