mirror of
https://git.sleeping.town/mirrors/foxy-moxy
synced 2024-12-22 06:15:29 +00:00
Merge pull request #9 from Patreon/luke---return-images
Luke return images
This commit is contained in:
commit
5cce6f4b04
1 changed files with 9 additions and 7 deletions
16
server.js
16
server.js
|
@ -42,25 +42,27 @@ var app = express();
|
|||
app.use(express.static(__dirname + '/images'));
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
var fileNames = writeFoxesToDisk(200, 200, 28);
|
||||
var images = fileNames.map(fileName => '<img src="/' + fileName + '"/>');
|
||||
res.send(images.join(''));
|
||||
var width = 400;
|
||||
var seed = uuid();
|
||||
var canvas = composeImage(width, width, seed);
|
||||
res.type('png');
|
||||
res.end(canvas.toBuffer(), 'binary');
|
||||
});
|
||||
|
||||
app.get('/:width', function(req, res) {
|
||||
var width = parseInt(req.params.width) || 400;
|
||||
var seed = uuid();
|
||||
var canvas = composeImage(width, width, seed);
|
||||
var fileName = writeFoxToDisk(canvas, seed);
|
||||
res.send('<img src="/' + fileName + '"/>');
|
||||
res.type('png');
|
||||
res.end(canvas.toBuffer(), 'binary');
|
||||
});
|
||||
|
||||
app.get('/:width/:seed', function(req, res) {
|
||||
var width = parseInt(req.params.width) || 400;
|
||||
var seed = sanitize(req.params.seed) || uuid();
|
||||
var canvas = composeImage(width, width, seed);
|
||||
var fileName = writeFoxToDisk(canvas, seed);
|
||||
res.send('<img src="/' + fileName + '"/>');
|
||||
res.type('png');
|
||||
res.end(canvas.toBuffer(), 'binary');
|
||||
});
|
||||
|
||||
app.listen(process.env.PORT || 3000);
|
||||
|
|
Loading…
Reference in a new issue