pack images with pngjs

https://www.npmjs.com/package/pngjs
This commit is contained in:
Mike Morris
2015-05-15 16:40:26 -04:00
parent 830a9b3972
commit 7ed3667092
7 changed files with 115 additions and 77 deletions

View File

@@ -5,6 +5,7 @@
var mbgl = require('..');
var fs = require('fs');
var path = require('path');
var PNG = require('pngjs').PNG;
var base = path.join(path.dirname(process.mainModule.filename), '../test');
@@ -20,10 +21,19 @@ fileSource.cancel = function(req) {
var map = new mbgl.Map(fileSource);
map.load(require('../test/fixtures/style.json'));
map.render({}, function(err, image) {
map.render({}, function(err, data) {
if (err) throw err;
mbgl.compressPNG(image, function(err, png) {
fs.writeFileSync('image.png', png);
console.warn('Written image.png');
var png = new PNG({
width: data.width,
height: data.height
});
png.data = data.pixels;
png.pack()
.pipe(fs.createWriteStream('image.png'))
.on('finish', function() {
console.warn('Written image.png');
});
});