mardi 10 juin 2014

Resize an image with node js

Resize an image with gm & node js:
var fs = require('fs')
 , gm = require('gm')
 , express = require('express');

var port = (process.env.VCAP_APP_PORT || 3000);

var app = module.exports = express();

app.get('/image', function (req, res) {

 gm('DSC03282.JPG')
  .resize(width, height)
  .noProfile()
  .toBuffer(function (err, buffer) {
   res.writeHead(200, {'Content-Type': 'image/jpeg' });
   res.end(buffer, 'binary');
  });
});

app.listen(port);
console.log("Go Image API : 3000");

3 commentaires: