webp文件是的谷歌制定的文件,编码和解码固然要用谷歌本身提供的工具libwebp,被整这些有的没的。
- 下载对应平台的libwebp
- 解压获得二进制文件,在bin目录下(编程的使用include和lib目录下的文件),如下是以windows 64bit为例,摘自readme.txt。详细的可使用
-h
选项查看具体的用法。
bin/cwebp.exe |
encoding tool |
bin/dwebp.exe |
decoding tool |
bin/gif2webp.exe |
gif conversion tool |
bin/vwebp.exe |
webp visualization tool |
bin/webpinfo.exe |
webp analysis tool |
lib/ |
static libraries |
include/webp |
headers |
test.webp |
a sample WebP file |
test_ref.ppm |
the test.webp file decoded into the PPM format |
- 其余 --> webp:
cwebp [-preset <...>] [options] in_file [-o out_file]
- webp --> 其余:
dwebp in_file [options] [-o out_file]
- 不指明格式默认转成PNG格式
- webp文件名不能有空格
- 批量转的话那就是脚本的事了,例如Python3脚本批量将webp转png(转换成png后再转成其余格式就很简单了):
import os
import sys
decoder_path = r"path/to/dwebp.exe" # Windows10下其实也支持斜杠/路径
webp_path = r"path/to/webp" # webp文件所在目录,webp文件名不能有空格!
res_path = r"path/to/png_res" # 存储转换后图片的目录,假设是png
if not os.path.exists(res_path) :
os.mkdir("result")
for f in os.listdir(webp_path):
res_f = str(f).replace(".webp", ".png") # 若webp文件命名有特殊,这里须要改改映射规则
cmd = "{0} {1} -o {2}".format(
decoder_path, os.path.join(webp_path, f), os.path.join(res_path, res_f))
os.system(cmd)