Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fsmunoz
Last active April 20, 2017 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fsmunoz/1cd2b6c9f29b0eb6dfac8827b991d72d to your computer and use it in GitHub Desktop.
Save fsmunoz/1cd2b6c9f29b0eb6dfac8827b991d72d to your computer and use it in GitHub Desktop.
// The JPEGINATOR
// OpenWhisk action to convert images to JPEG
//
// Author: Frederico Munoz <frederico.munoz@pt.ibm.com>
// Data: APR 2017
// License: Eclipse Public License 1.0
var fs = require('fs');
var gm = require('gm').subClass({imageMagick: true});
function main (params) {
var b64string = params.image;
var buf = Buffer.from(b64string, 'base64')
return new Promise(function(resolve, reject) {
gm(buf).toBuffer('JPEG', function (err, buffer) {
if (err)
{
console.log("Error");
return {result: "error"};
} else {
console.log("Success");
resolve({headers: { 'Content-Type': 'image/jpeg' },
statusCode: 200,
body: buffer.toString('base64')});
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment