Skip to main content
Travis build PyPI version Python version

一个将 PNG、JPG、JPEG、BMP、GIF 等格式的图像文件批量 (递归) 转换为 webp 格式的 Python 脚本

可以设定压缩级别 (0 ~ 100),数字越大品质越好。支持无损压缩。支持多线程。

可以在 GNU/Linux 上运行,Mac OS 估计也可以 (没测试过),Windows 上可能要修改一下才能用 (主要是目录地址中 / 与 \ 的区别)

突然发现 webp 的工具包中有一个叫 img2webp 的工具 (没用过所以不知道QAQ),为了避免冲突现将项目改名为 fast2webp _(:з」∠)_

依赖

  • Python3

  • webp

安装

sudo pip3 install fast2webp

使用

fast2webp [options] <value>

截图

https://f.cangg.cn:82/data/201812132140465668.gif

参数 (options)

usage: fast2webp [-h] [-i <dir>] [-o <dir>] [-q <int> | -lossless][-t <int>]
                [-only {png,jpg,bmp,gif}] [-enable_gif] [-uncopy]

-i <dir> .......... 需要转换的文件所在的目录,会递归进行转换  (默认:.[当前目录])
-o <dir> .......... *.webp 文件的输出目录,输出目录结构与输入目录保持一致 (默认:./output)
                    如果输出目录不存则会按照给定的路径新建文件夹
                    如果缺省,则会在当前目录中新建并输出到目录 'output'
-q <int> .......... 与 'cwebp' 中相同;表示压缩的程度 (0 ~ 100),数字越大品质越好 (默认:80)
-t <int> .......... 线程池中线程的个数;数字越大转换速度越快。当然,也更吃资源 (默认:10)
-lossless ......... 与 'cwebp' 中相同;无损压缩
-only <value> ..... 只执行某单一任务 (可接受的值有:png、jpg、bmp、gif)
                    例如:-only png 表示只转换输入目录中的 png 文件为到输出目录
-enable_gif ....... 将 gif 转为 webp (默认情况下会跳过 gif 文件)
                    转换 gif 文件比较吃资源,慎用
                    转换 gif 文件不支持无损压缩,此时 -lossless = -q 100
-uncopy ........... 默认情况下会将非图片文件复制到输出目录中,使用参数 -uncopy 关闭这一特性
                    (*.webp 和 *.gif 仍会被复制)
-h ................ 展示帮助信息

TODO

  • 支持 Windows

  • 支持更多的参数

Metadata

Release files for fast2webp 1.1.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fast2webp 1.1.11
File Size Uploaded
fast2webp-1.1.11.tar.gz 7.2 kB Details

Release files / fast2webp-1.1.11.tar.gz

Download URL fast2webp-1.1.11.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5043cc42b329e171f846ee6036cc149c62342618bc884ece433aff37fcc728fc
BLAKE2b-256 checksum
How to use checksums
e8dc7b54c3989e0e54597bad58bef6db5f082dc3c9d408ea1605c06698592b4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

Release history Release notifications | RSS feed

This release

1.1.11 This release

1 release file

1.1.10

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page