[REQ_RESOURCE_TYPE]:资源必须是字符串、Buffer或有效的文件流
Posted
技术标签:
【中文标题】[REQ_RESOURCE_TYPE]:资源必须是字符串、Buffer或有效的文件流【英文标题】:[REQ_RESOURCE_TYPE]: The resource must be a string, Buffer or a valid file stream 【发布时间】:2021-04-04 17:16:33 【问题描述】:我正在尝试在图片中做一些灰度效果,但是当我执行命令时,它会显示上面的错误...
有什么办法吗?
守则:
const jimp = require('jimp')
const MessageAttachment = require('discord.js')
module.exports =
name:'grey',
run:async(client, message, args)=>
if (message.attachments.size > 0)
let image = message.attachments.first().url;
if(!image) return;
let readedImage = await jimp.read(image);
let sendedImage = await readedImage.greyscale()
let attch = new MessageAttachment(sendedImage,'Skyy.png');
message.channel.send(attch);
【问题讨论】:
【参考方案1】:您必须在发送 jimp 图像之前将其转换为缓冲区:
const jimp = require('jimp')
const MessageAttachment = require('discord.js')
module.exports =
name:'grey',
run:async(client, message, args)=>
if (message.attachments.size > 0)
let image = message.attachments.first().url;
if(!image) return;
let readedImage = await jimp.read(image);
// changed line below
let sendedImage = await readedImage.greyscale().getBufferAsync();
let attch = new MessageAttachment(sendedImage,'Skyy.png');
message.channel.send(attch);
【讨论】:
以上是关于[REQ_RESOURCE_TYPE]:资源必须是字符串、Buffer或有效的文件流的主要内容,如果未能解决你的问题,请参考以下文章
fclose(): 参数 #1 ($stream) 必须是资源类型,bool 给定
强烈推荐的TensorFlowPytorch和Keras的样例资源(深度学习初学者必须收藏)