lib/utils/page.js
function convertImages(images, options) {
    if (!options.convertImages) return Q();

    var downloaded = [];
    options.book.log.debug.ln('convert ', images.length, 'images to png');

    return batch.execEach(images, {
        max: 100,
        fn: function(image) {
            var imgin = path.resolve(options.book.options.output, image.source);

            return Q()

            // Write image if need to be download
            .then(function() {
                if (!image.origin && !_.contains(downloaded, image.origin)) return;
                options.book.log.debug('download image', image.origin, '...');
                downloaded.push(image.origin);
                return options.book.log.debug.promise(fs.writeStream(imgin, request(image.origin)))
                .fail(function(err) {
                    if (!_.isError(err)) err = new Error(err);

                    err.message = 'Fail downloading '+image.origin+': '+err.message;
                    throw err;
                });
            })

            // Write svg if content
            .then(function() {
                if (!image.content) return;
                return fs.writeFile(imgin, image.content);
            })

            // Convert
            .then(function() {
                if (!image.dest) return;
                var imgout = path.resolve(options.book.options.output, image.dest);
                options.book.log.debug('convert image', image.source, 'to', image.dest, '...');
                return options.book.log.debug.promise(imgUtils.convertSVG(imgin, imgout));
            });
        }
    })
    .then(function() {
        options.book.log.debug.ok(images.length+' images converted with success');
    });
}
function convertImages(images, options) {
    if (!options.convertImages) return Q();

    var downloaded = [];
    options.book.log.debug.ln('convert ', images.length, 'images to png');

    return batch.execEach(images, {
        max: 100,
        fn: function(image) {
            var imgin = path.resolve(options.book.options.output, image.source);

            return Q()

            // Write image if need to be download
            .then(function() {
                if (!image.origin && !_.contains(downloaded, image.origin)) return;
                options.book.log.debug('download image', image.origin, '...');
                downloaded.push(image.origin);
                return options.book.log.debug.promise(fs.writeStream(imgin, request(image.origin)))
                .fail(function(err) {
                    if (!_.isError(err)) err = new Error(err);

                    err.message = 'Fail downloading '+image.origin+': '+err.message;
                    throw err;
                });
            })

            // Write svg if content
            .then(function() {
                if (!image.content) return;
                return fs.writeFile(imgin, image.content);
            })

            // Convert
            .then(function() {
                if (!image.dest) return;
                var imgout = path.resolve(options.book.options.output, image.dest);
                options.book.log.debug('convert image', image.source, 'to', image.dest, '...');
                return options.book.log.debug.promise(imgUtils.convertSVG(imgin, imgout));
            });
        }
    })
    .then(function() {
        options.book.log.debug.ok(images.length+' images converted with success');
    });
}
function convertImages ( images , options ) { if ( ! options . convertImages ) return Q ( ) ; var downloaded = [ ] ; options . book . log . debug . ln ( 'convert ' , images . length , 'images to png' ) ; return batch . execEach ( images , { max : 100 , fn : function ( image ) { var imgin = path . resolve ( options . book . options . output , image . source ) ; return Q ( ) // Write image if need to be download . then ( function ( ) { if ( ! image . origin && ! _ . contains ( downloaded , image . origin ) ) return ; options . book . log . debug ( 'download image' , image . origin , '...' ) ; downloaded . push ( image . origin ) ; return options . book . log . debug . promise ( fs . writeStream ( imgin , request ( image . origin ) ) ) . fail ( function ( err ) { if ( ! _ . isError ( err ) ) err = new Error ( err ) ; err . message = 'Fail downloading ' + image . origin + ': ' + err . message ; throw err ; } ) ; } ) // Write svg if content . then ( function ( ) { if ( ! image . content ) return ; return fs . writeFile ( imgin , image . content ) ; } ) // Convert . then ( function ( ) { if ( ! image . dest ) return ; var imgout = path . resolve ( options . book . options . output , image . dest ) ; options . book . log . debug ( 'convert image' , image . source , 'to' , image . dest , '...' ) ; return options . book . log . debug . promise ( imgUtils . convertSVG ( imgin , imgout ) ) ; } ) ; } } ) . then ( function ( ) { options . book . log . debug . ok ( images . length + ' images converted with success' ) ; } ) ; }
Convert svg images to png
Convert svg images to png