JIMP在nodejs中无效的文件签名
我使用JIMP将我的图像转换为灰度,并降低其质量。但是对于2%的情况下,它正在损坏我的形象,并在控制台中抛出一个错误 – “错误:无效的文件签名在Parser._parseSignature(C:\ Users \ Akshay \ Desktop \ darwin \ node_modules \ pngjs \ lib \ parser.js:50:18)“如果问题代码如下:
var ext=path.extname(dest); if(ext!='.jpg'){ dest=replaceExt(dest, '.jpg'); } console.log(path.extname(dest)); var file = fs.createWriteStream(dest); ////console.log(url) if(url.indexOf('https')!=-1){ //console.log("https") var request = https.get(url, function(response) { response.pipe(file); file.on('finish', function() { Jimp.read(dest).then(function (lennaa) { lennaa.resize(256, 256) // resize .quality(90) // set JPEG quality .greyscale() // set greyscale .write(dest); // save }).catch(function (err) { console.error(err); }); file.close(cb); // close() is async, call cb after close completes. }); }).on('error', function(err) { // Handle errors fs.unlink(dest); // Delete the file async. (But we don't check the result) if (cb) cb(err.message); }); }
我面临同样的问题,看来问题是,尽pipe我们尽了最大的努力,但以前的文件还没有写完。
所以我用一种愚蠢的,可耻的方式做了这个,并且在读取失败的情况下加了一个半秒的延迟。
let image; try { image = await Jimp.read(filepath); } catch (error) { debug(`Error reading ${filepath}. But we'll try again!`); // Wait half second, try again. What an ugly hack. It might as well work. let temp = await new Promise(resolve => setTimeout(resolve, 600)); try { image = await Jimp.read(filepath); debug('Success reading file on second attempt!'); } catch (error2) { // If totally failed, at least exit gracefully: this.session.send('The bot is a little busy now. Please try again.'); this.session.endDialog(); } }
- Nodejs创build一个带有文本的PNG图像
- 我可以使用node-gm调整内存中的图像大小,还是需要先将其保存起来?
- graphicsmagick裁剪取决于原始图像大小(resuse readstream)
- node.js是图像代理和操作任务的理想select吗?
- 无法将stream作为parameter passing给aspnet.core.NodeServices中的JS
- 使用node.js调整图像大小
- 如何检测Node.js中损坏的图像文件?
- 如何在运行时在Node.js中执行一系列的image processing步骤
- 用javascript创buildInstagram-esquefilter?