如何解决NodeJS 从网络流图像,转换为 WebP
我需要从网络流式传输 jpg 格式的图像(此处使用虚拟图像),然后将它们转换为 WebP。这是一次一个对话(非批量)
我有以下代码可以成功提取图像并将其保存为 .jpg。
const axios = require("axios")
const fs = require("fs")
const imagemin = require("imagemin")
const imageminWebp = require("imagemin-webp")
async function axios_get_contents (uri,callback) {
await axios({
"method": "get","url": uri,"responseType": "stream"
}).
then((response) => {
console.log("then1")
response.data.pipe(fs.createWriteStream("pic1.jpg"))
})
}
const URL = "https://images.pexels.com/photos/1449767/pexels-photo-1449767.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260"
axios_get_contents(URL).then((ret) => console.log(ret))
下面是我被卡住的地方。我正在尝试转换为 webp。本质上,imagemin 代码在创建 jpg 之前运行。
async function axios_get_contents (uri,"responseType": "stream"
}).
then((response) => {
console.log("then1")
response.data.pipe(fs.createWriteStream("pic1.jpg"))
}).
then((response) => {
console.log("then2")
imagemin(["pic1.jpg"],{
"destination": "compressed-images","plugins": [imageminWebp({"quality": 50})]
})
})
}
问题:
如何成功链接 webp 转换?
我需要先写一个 jpg 文件,然后再将同一个文件读回 imagemin 吗?我可以将缓冲区/var 传递给 imagemin 吗?会节省阅读和写作。
感谢堆!!
解决方法
这些都对我有用
<video preload muted autoplay loop id="sty">
<source src="content/1/sty.mp4" type="video/mp4">
</video>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。