node 图片压缩(使用tinify)

What does TinyPNG do?

TinyPNG uses smart lossy compression techniques to reduce the file size of your WEBP, JPEG and PNG files. By selectively decreasing the number of colors in the image, fewer bytes are required to store the data. The effect is nearly invisible but it makes a very large difference in file size!

Why should I use TinyPNG?

PNG is useful because it’s the only widely supported format that can store partially transparent images. The format uses compression, but the files can still be large. Use TinyPNG to shrink images for your apps and sites. It will use less bandwidth and load faster.

Can anyone tell the difference?

Excellent question! Let me give you a side by side comparison. Below are two photos of my cousin. The left image is saved as 24-bit PNG directly from Adobe Photoshop. On the right is the same image processed by TinyPNG. Spot any difference?

TinyPNG做什么?


TinyPNG使用智能有损压缩技术来减少WEBP、JPEG和PNG文件的文件大小。通过选择性地减少图像中的颜色数量,存储数据所需的字节更少。这种效果几乎看不见,但它在文件大小上有很大的差异!

为什么我应该使用TinyPNG?


PNG很有用,因为它是唯一被广泛支持的可以存储部分透明图像的格式。格式使用压缩,但文件仍然可能很大。使用TinyPNG缩小应用程序和网站的图像。它将使用更少的带宽和更快的加载。

有人能分辨出区别吗?


好问题!让我给你一个并列比较。下面是我表哥的两张照片。左侧图像直接从Adobe Photoshop保存为24位PNG。右侧是TinyPNG处理的同一图像。有什么区别吗?



https://tinify.com/dashboard/api

const tinify = require('tinify')
tinify.key = 'xxx'

//图片压缩
const toolsTinyImg = async (req, res) => {
  const { dirPath = 'D:/temp/yuying/video/grade1/chinese1' } = req.body
  let imgDirPath = dirPath + '-img'

  const imgArr = fs.readdirSync(imgDirPath)
  imgArr.forEach((item, index) => {
    console.log(item)
    const source = tinify.fromFile(`${imgDirPath}/${item}`)
    source.toFile(`${imgDirPath}/${item}`)
  })

  res.send({
    code: 200,
    data: {
      imgDirPath
    },
    message: '成功'
  })
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

徐同保

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值