我制作了以下字符串,尝试解码 base64 编码图像并使用缓冲区通过 gm 处理它:
const gm=require('gm');
const URLSafeBase64 = require('urlsafe-base64');
const iconv = require('iconv-lite');
const fs=require('fs');
//Content too bit to put it inside the script
var base64Data="iVBORw0KGgoAAAANSUhEUg....AAA3NCSVQICAjb4U/gAASuQmCC"
base64Data = base64Data.replace(/^data:\w*\/\w*;base64,/gm,'')
base64data = new Buffer(base64Data,'base64')
gm(base64Data).setFormat('png').size(function(err,value){
if(err){
return console.log("size error",err.message);
}
if(500 < value.width){
let ratio= width/value.width;
let newHeight=value.height*ratio;
this.resize(width,newHeight)
/**
* @var {Buffer} value
*/
.toBuffer(function(err,value){
if(err){
return console.log("Error: ",err)
}
fs.writeSync('./image.png',value.toString('binary'));
});
} else {
fs.writeSync('./image.png',buffer.toString('binary'));
}
});
但是当我尝试调整它时,我收到以下错误:
大小错误产生 E2BIG
你知道为什么会这样吗?