You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何使用CLI命令将WebP图片转换为JPG格式?

WebP转JPG的CLI命令与方法

嘿,这里有几个实用的CLI工具能帮你快速把WebP格式转换成JPG,我把具体用法和细节都整理好了:

1. 使用ImageMagick(跨平台通用)

ImageMagick是一款功能强大的图像处理工具,几乎支持所有主流操作系统,转格式的操作非常直观。

安装方法

  • Debian/Ubuntu系
    sudo apt update && sudo apt install imagemagick
    
  • macOS(需先安装Homebrew):
    brew install imagemagick
    
  • Windows(用Chocolatey包管理器):
    choco install imagemagick
    

转换命令

  • 单文件转换:
    convert input.webp output.jpg
    
  • 自定义输出质量(数值0-100,越高画质越好、文件体积越大):
    convert input.webp -quality 90 output.jpg
    
  • 批量转换当前目录下所有WebP文件:
    Bash/Linux终端
    for f in *.webp; do convert "$f" "${f%.webp}.jpg"; done
    
    Windows PowerShell
    Get-ChildItem -Filter *.webp | ForEach-Object { magick $_.FullName ($_.FullName -replace '\.webp$', '.jpg') }
    

2. 使用Google官方的dwebp工具

dwebp是Google WebP工具包中的专用解码工具,轻量且针对性强,适合只需要处理WebP格式的场景。

安装方法

  • Debian/Ubuntu系
    sudo apt update && sudo apt install webp
    
  • macOS
    brew install webp
    
  • Windows:下载Google WebP官方工具包解压后,将dwebp.exe所在路径添加到系统环境变量即可。

转换命令

  • 单文件转换:
    dwebp input.webp -o output.jpg
    
  • 批量转换当前目录下所有WebP文件(Bash):
    for f in *.webp; do dwebp "$f" -o "${f%.webp}.jpg"; done
    

注意事项

  • JPG格式不支持透明通道,如果你的WebP图片包含透明区域,转换后透明部分会默认变为白色。若需保留透明效果,建议转成PNG格式。
  • 调整质量参数时,70-90是兼顾画质和文件体积的常用区间,可根据需求自行调整。

内容的提问来源于stack exchange,提问作者lmlmlm

火山引擎 最新活动