Go

jpg,jpeg,pngconfig.json
  • 目前支持的图像格式:JPEG,PNG,BMP,GIF(目前为静态图像)
https://a.com/1.jpgimage/webp

基本使用步骤

config.jsonIMG_PATHhttps://example.com/pics/tsuki.jpg/var/www/image/pics/tsuki.jpgIMG_PATH/var/www/imageEXHAUST_PATHwebpEXHAUST_PATH/var/cache/webp/var/cache/webp/pics/tsuki.jpg.1582558990.webp

1. 下载或构建二进制文件

webp-server

想要构建自己的二进制文件?查看 build 部分

2. 配置文件

config.json
{
    "HOST": "127.0.0.1",
    "PORT": "3333",
    "QUALITY": "80",
    "IMG_PATH": "/path/to/pics",
    "EXHAUST_PATH": "/path/to/exhaust",
    "ALLOWED_TYPES": ["jpg","png","jpeg"]
}

3. 运行

./webp-server --help
Usage of ./webp-server:
  -child
        is child process
  -config string
        /path/to/config.json. (Default: ./config.json) (default "config.json")
  -dump-config
        Print sample config.json
  -dump-systemd
        Print sample systemd service file.
  -jobs int
        Prefetch thread, default is all. (default 8)
  -prefetch
        Prefetch and convert image to webp
  -prefork
        use prefork

预读

预读会将你的所有图像转换为 webp. 不要担心, WebP 服务器将启动, 你不必等到预读完成.

./webp-server -prefetch
-jobs=4
# use 4 cores
./webp-server -prefetch -jobs=4

转储配置文件 config.json

config.json>
./webp-server -dump-config > config.json

转储 systemd 服务文件

>
./webp-server -dump-systemd

screen 或 tmux

screentmuxscreen
screen -S webp
./webp-server --config /path/to/config.json
webp-serverscreen

systemd

Don't worry, we've got you covered!
不用担心, 我们会覆盖你的内容!

webp-server/opt/webps/webp-server/opt/webps/config.json
./webp-server -dump-systemd > /lib/systemd/system/webp-server.service
systemctl daemon-reload
systemctl enable webps.service
systemctl start webps.service

4. Nginx proxy_pass

proxy_pass http://localhost:3333/;

WordPress 示例

location ^~ /wp-content/uploads/ {
        proxy_pass http://127.0.0.1:3333;
}