Created
October 30, 2017 07:16
-
-
Save autumnharmony/b48eda94dee6358441d41ceb0d241e50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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