当使用bas64string作为参数调用时,节点gm(imagemagick)似乎不起作用

我没有得到任何输出图像时,图像不是path&是基地64编码图像。

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

您需要将Base64string转换为一个缓冲区 :

 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!"); }); 
  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); });