torque/test/support/image.js
Raul Ochoa 916871365f image.compare returns the % difference against the reference image
As canvas can differ from one implementation to another make tests
to have a tolerance to differences.
2015-03-04 18:53:06 +01:00

20 lines
540 B
JavaScript

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);
return img.compare(reference) / (reference.width() * reference.height());
}
function save(path, buffer) {
var img = new mapnik.Image.fromBytesSync(buffer);
img.save(path);
}
module.exports = {
compare: compare,
save: save
};