2015-03-05 00:23:08 +08:00
|
|
|
var mapnik = require('mapnik');
|
|
|
|
|
|
|
|
function compare(buffer, fixtureRelPath) {
|
|
|
|
save(__dirname + '/../results/' + fixtureRelPath, buffer);
|
|
|
|
|
|
|
|
var img = new mapnik.Image.fromBytesSync(buffer);
|
|
|
|
var reference = new mapnik.Image.openSync(__dirname + '/../fixtures/image/' + fixtureRelPath);
|
2015-03-05 01:53:06 +08:00
|
|
|
return img.compare(reference) / (reference.width() * reference.height());
|
2015-03-05 00:23:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function save(path, buffer) {
|
|
|
|
var img = new mapnik.Image.fromBytesSync(buffer);
|
|
|
|
img.save(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
compare: compare,
|
|
|
|
save: save
|
|
|
|
};
|