这个sharp到底怎么用的啊,为什么这样子会返回一串乱码
const server = http.createServer(async (req, res) => {
// 调用 updateuserId 函数
await updateuserId();
await new Sharp({
create: {
width: 200,
height: 100,
channels: 3,
background: { r: 255, g: 255, b: 255 }
},
text: {
width: 200,
height: 100,
font: 'sans',
text: `${userId}`
}
})
.png()
.toBuffer()
.then(imageBuffer => {
// 设置响应头
res.writeHead(200, { 'Content-Type': 'image/png' });
// 返回图片
res.end(imageBuffer);
})
});
// 服务器监听 6541 端口
server.listen(6541, () => {
console.log('Server is running on http://localhost:6541');
});
