2.0.0 • Published 5 years ago

img-spriter v2.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

img-spriter

image sprite generator

API

process(imageFrames )

Processed image objects, increase information field imageInfo

  • imageFrames - Image array

    • imageUrl required, local file absolute path e.g: /User/home/a.png
// input 
[{
  imageUrl: '/Users/home/a.png'
}]
// output
[{
  imageUrl: '/Users/home/a.png',
  imageInfo: {
    image: Stream,
    width: Number,
    height: Number,
  }
}]

processHTTP(imageFrames )

Like the process, but imageUrl is a http link address

sprite(imageFrames , options)

Image sprite generator

  • iamgeFrames - Image array
  • options

    • margin - default: 5 Icon margin
  • @return

{
  stream: Sprite image Stream,
  dataSource: icon coordinate information
}

Example

var data = [{
  imageUrl: 'http://img.alicdn.com/tps/i2/TB1fvaMLVXXXXbuXFXXEDhGGXXX-32-32.png',
  filename: 'acd',
  w: 32,
  h: 32
}, {
  imageUrl: 'http://img.alicdn.com/tps/i1/TB18_qELVXXXXaKXVXXEDhGGXXX-32-32.png',
  filename: 'ac12312',
  w: 32,
  h: 32
}, {
  imageUrl: 'http://img.alicdn.com/tps/i2/TB1sEiZLVXXXXXxXFXXEDhGGXXX-32-32.png',
  filename: 'ac12312',
  w: 32,
  h: 32
}]

imgSpriter.processHTTP(data)
  .then(function(data) {
    imgSpriter.sprite(data)
      .then(function(data) {
        var spriteOutput = path.join(__dirname, './sprite.png');

        fs.writeFileSync(
          './test/index-output.json',
          JSON.stringify(data.dataSource, null, 2)
        );
        data.stream.pack()
          .pipe(fs.createWriteStream(spriteOutput))
          .on('finish', function() {
            console.log('output image:', spriteOutput);
          });
      }).catch(function(err) {
        console.log(err);
      })
  }).catch(function(err) {
    console.log('========', err);
  })
2.0.0

5 years ago

0.3.6

7 years ago

0.3.5

8 years ago

0.3.4

8 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago