2

我不知道如何为 Kraken Image Optimizer(不是 KrakenJs)编写 Gruntfile:https ://github.com/kraken-io/kraken-node

例如,grunt-contrib-imagemin 的 Gruntfile 类似于:

    imagemin: {                          // Task
        static: {                          // Target
            options: {                       // Target options
                optimizationLevel: 3,
                //use: [mozjpeg()]
            },
            files: {                         // Dictionary of files
                'dist/img.png': 'src/img.png', // 'destination': 'source'
                'dist/img.jpg': 'src/img.jpg',
                'dist/img.gif': 'src/img.gif'
            }
        },
        dynamic: {                         // Another target
            files: [{
                expand: true,                  // Enable dynamic expansion
                cwd: 'src/',                   // Src matches are relative to this path
                src: ['**/*.{png,jpg,gif}'],   // Actual patterns to match
                dest: 'dist/'                  // Destination path prefix
            }]
        }
    },

然而,在 NodeJs 上使用 Kraken 的文档如下所示:

    var Kraken = require('kraken');

    var kraken = new Kraken({
        'api_key': 'your-api-key',
        'api_secret': 'your-api-secret'
    });

    var params = {
        file: '/path/to/image/file.jpg',
        wait: true
    };

    kraken.upload(params, function(status) {
        if (status.success) {
            console.log('Success. Optimized image URL: %s', status.kraked_url);
        } else {
            console.log('Fail. Error message: %s', status.error);
        }
    });



    // For advanced API usage simply alter the `params` object. For example:

    var params = {
        file: '/path/to/image/file.jpg',
        wait: true,
        resize: {
            width: 100,
            height: 75,
            strategy: 'crop'
        },
        s3_store: {
            key: 'AKIAO4AD5J4F1NA33Q12',
            secret: 'AAwQwJSEgG9WpeCV20GlHI5hGKxKuw5qY80t4CCe',
            bucket: 'assets',
            path: 'images/layout/header.jpg'
        },
        webp: true,
        lossy: true
    };

如何将其转换为在我的 Gruntfile 中有效的东西?

4

0 回答 0