问题描述
我正在尝试在我的 nodejs 服务器上使用 imagemin.buffer() 和“imagemin-mozjpeg”插件。
我的目标是使用 axios(作为缓冲区)从 url 下载外部图像,使用 imagemin-mozjpeg(有损压缩)对其进行压缩,然后返回压缩后的图像缓冲区。
我的代码运行没有任何错误。但由于某种原因,返回的缓冲区与原始缓冲区相同(因此,由于某种原因未应用压缩)。
我的代码:
const axios = require('axios');
const imagemin = require('imagemin');
const imageminMozjpeg = require('imagemin-mozjpeg');
export async function compress() {
console.log("COMPRESS CALLLED");
const initialBuffer = await axios.get('https://yt3.ggpht.com/ytc/AKedOLQZtTtwHGLWHDlhHaTvLw5RH9I-9oGOsv8_8FBm=s151-c-k-c0x00ffffff-no-rj',{
responseType: 'arraybuffer'
})
.then(response => {
return Buffer.from(response.data);
});
const compressedBuffer = await imagemin.buffer(initialBuffer,{
use: [
imageminMozjpeg({
quality: 40
})
]
});
return compressedBuffer;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)