src/ispriter.js
function readImageInfo(fileName, callback) {
    fileName = path.join(spriteConfig.workspace, fileName);
    fs.createReadStream(fileName).pipe(new PNG())
        .on('parsed', function() {

            var imageInfo = {
                image: this,
                width: this.width,
                height: this.height
            };

            getImageSize(this, function(size) {

                imageInfo.size = size;
                callback(imageInfo);
            });
        })
        .on('error', function(e) {
            info('>>Skip: ' + e.message + ' of "' + fileName + '"');
            callback(null);
        });
}
function readImageInfo(fileName, callback) {
    fileName = path.join(spriteConfig.workspace, fileName);
    fs.createReadStream(fileName).pipe(new PNG())
        .on('parsed', function() {

            var imageInfo = {
                image: this,
                width: this.width,
                height: this.height
            };

            getImageSize(this, function(size) {

                imageInfo.size = size;
                callback(imageInfo);
            });
        })
        .on('error', function(e) {
            info('>>Skip: ' + e.message + ' of "' + fileName + '"');
            callback(null);
        });
}
function readImageInfo ( fileName , callback ) { fileName = path . join ( spriteConfig . workspace , fileName ) ; fs . createReadStream ( fileName ) . pipe ( new PNG ( ) ) . on ( 'parsed' , function ( ) { var imageInfo = { image : this , width : this . width , height : this . height } ; getImageSize ( this , function ( size ) { imageInfo . size = size ; callback ( imageInfo ) ; } ) ; } ) . on ( 'error' , function ( e ) { info ( '>>Skip: ' + e . message + ' of "' + fileName + '"' ) ; callback ( null ) ; } ) ; }
读取单个图片的内容和信息
@param {String} fileName
@param {Function} callback callback(ImageInfo)
{ // ImageInfo
image: null, // 图片数据
width: 0,
height: 0,
size: 0 // 图片数据的大小
}
读取单个图片的内容和信息