Skip to content

pngquant

什么是 pngquant?

pngquant 是一个用于压缩 PNG 图像文件的工具。它可以显著减小 PNG 文件的大小,同时保持图像质量和透明度。通过减小文件大小,可以提高网页加载速度,并节省存储空间。pngquant 提供命令行接口和库,可轻松集成到各种应用程序和脚本中。

Nodejs 中 调用 pngquant

同样还是可以用exec命令调用

js
import { exec } from 'child_process';
exec('pngquant 73kb.png --output test.png');

73kb 压缩完 之后 22kb

js
import { exec } from 'child_process';
exec('pngquant 73kb.png --quality=82 --output test.png');

quality表示图片质量0-100值越大图片越大效果越好

js
import { exec } from 'child_process';
exec('pngquant 73kb.png --speed=1 --quality=82 --output test.png');
  • --speed=1: 最慢的速度,产生最高质量的输出图像。

  • --speed=10: 最快的速度,但可能导致输出图像质量稍微降低。

Keep Reading, Keep Writing, Keep Coding