Skip to content

Instantly share code, notes, and snippets.

@kvendrik
Last active January 25, 2016 18:15
Show Gist options
  • Select an option

  • Save kvendrik/81ca057c0c21d79283f0 to your computer and use it in GitHub Desktop.

Select an option

Save kvendrik/81ca057c0c21d79283f0 to your computer and use it in GitHub Desktop.
Placeholder API
npm i gm express
var gm = require('gm'),
app = require('express')();
app.get('/:width/:height', function(req, res){
gm('download.jpeg')
.resize(req.params.width, req.params.height, '^')
.gravity('Center')
.crop(req.params.width, req.params.height)
.toBuffer('PNG',function(err, buffer){
if(err){
console.error(err);
return err;
}
res.set('Content-Type', 'image/png;base64');
res.end(buffer);
});
});
app.listen(3000);
{
"name": "placeholder-api",
"version": "0.1.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Koen Vendrik <[email protected]>",
"license": "MIT"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment