Skip to content

Instantly share code, notes, and snippets.

@autumnharmony
Created October 30, 2017 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save autumnharmony/b48eda94dee6358441d41ceb0d241e50 to your computer and use it in GitHub Desktop.
Save autumnharmony/b48eda94dee6358441d41ceb0d241e50 to your computer and use it in GitHub Desktop.
var fs = require('fs'),
gm = require('gm').subClass({
imageMagick: true
});
module.exports = MockBase => class MockRivers extends MockBase {
mocks(options) {
return [{
route: '/tiles/:z/:x\::y/tile.png',
responses: [{
request: {
method: 'GET'
},
response: function(ctx, z, x, y) {
ctx.respond = false;
ctx.type = "image/png";
ctx.res.writeHead(200, {
'Content-Type': 'image/png'
});
var color = x * y * z;
color = String("000000" + color).slice(-6);
gm(256, 256, "#" + color)
.fontSize(20)
.drawText(10, 50, "/" + z + "/" + x + ":" + y)
.drawText(10, 100, "/tile.png")
.toBuffer("PNG", function(err, buffer) {
if (err) console.log(err);
ctx.res.write(buffer);
ctx.res.end();
});
}
}]
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment