npm i gm express
Last active
January 25, 2016 18:15
-
-
Save kvendrik/81ca057c0c21d79283f0 to your computer and use it in GitHub Desktop.
Placeholder API
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 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); |
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
| { | |
| "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