超好用的在线图片压缩源码,让你轻松将图片极限无损压缩

今天找到的图片压缩源码,支持.jpg、.png、.webp、.wp2、.jxl、.avif等多种格式压缩,Cli还支持批量压缩,非常好用!

Demo:https://buyao.vip/index.php?c=click&id=86

部署:

已宝塔为例,安装PM2管理器,上传源文件,运行以下代码:

npm install
npm run build
#运行开发模式
npm run dev

将目录指定为build目录即可使用!

uTools 1620290420115 1024x454 - 超好用的在线图片压缩源码,让你轻松将图片极限无损压缩

原图135KB,使用MozJPEG模式压缩,最终压缩减少70%,仅有39.9KB

批量压缩:

安装:

$ npx @squoosh/cli <options...>

当然,您也可以安装Squoosh CLI:

$ npm i -g @squoosh/cli
$ squoosh-cli <options...>

用法:

Usage: squoosh-cli [options] <files...>

Options:
  -V, --version                                          output the version number
  -d, --output-dir <dir>                                 Output directory (default: ".")
  -s, --suffix <suffix>                                  Append suffix to output files (default: "")
  --max-optimizer-rounds <rounds>                        Maximum number of compressions to use for auto optimizations (default: "6")
  --optimizer-butteraugli-target <butteraugli distance>  Target Butteraugli distance for auto optimizer (default: "1.4")
  --resize [config]                                      Resize the image before compressing
  --quant [config]                                       Reduce the number of colors used (aka. paletting)
  --rotate [config]                                      Rotate image
  --mozjpeg [config]                                     Use MozJPEG to generate a .jpg file with the given configuration
  --webp [config]                                        Use WebP to generate a .webp file with the given configuration
  --avif [config]                                        Use AVIF to generate a .avif file with the given configuration
  --jxl [config]                                         Use JPEG-XL to generate a .jxl file with the given configuration
  --wp2 [config]                                         Use WebP2 to generate a .wp2 file with the given configuration
  --oxipng [config]                                      Use OxiPNG to generate a .png file with the given configuration
  -h, --help                                             display help for command

源码下载:点击下载