2

当图像不是路径并且是 base 64 编码图像时,我没有得到任何输出图像。

    const image = 'base64 encoded string';

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

2 回答 2

1

您需要将 Base64 字符串转换为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!");
});
于 2017-10-16T11:37:52.823 回答
0
    const imageBuff = Buffer.from(image, 'base64');
     gm(imageBuff)
     .resize(72, 72)
     .strip()
     .write('../curber/newimage.png', function (err) {
    if (!err) console.log('done');

    else
     console.log(err.log, err.stack);
     });
于 2017-10-16T12:59:24.937 回答