Last active
April 20, 2017 19:11
-
-
Save fsmunoz/1cd2b6c9f29b0eb6dfac8827b991d72d to your computer and use it in GitHub Desktop.
This file contains 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
// The JPEGINATOR | |
// OpenWhisk action to convert images to JPEG | |
// | |
// Author: Frederico Munoz <[email protected]> | |
// 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