2

I'm not getting any output image when image is not path & is base 64 encoded image.

    const image = 'base64 encoded string';

    gm(image, ['jpeg'])
    .resize(72, 72)
    .strip()
    .write('./aks.png', function (err) {
    if (!err) console.log('done');
     });

1 Answers1

3

You need to convert the Base64 string to a Buffer:

var gm = require("gm");
var fs = require("fs");
var image = fs.readFileSync("input.png", "base64");

gm(Buffer.from(image, "base64"))
.resize(72, 72)
.strip()
.write("output.png", function(error) {
  if (error) return console.error(error);
  console.log("Done!");
});
Luke Horvat
  • 337
  • 1
  • 9