2020-03-01 19:33:18 +08:00
2020-02-29 18:39:00 +08:00
2020-02-29 18:39:00 +08:00
2020-02-29 18:39:00 +08:00
2020-02-26 20:23:10 +08:00
2020-02-09 14:32:29 +08:00
2020-02-29 18:39:00 +08:00
2020-02-09 12:21:51 +08:00
2020-02-09 14:32:00 +08:00
2020-02-29 18:38:56 +08:00
2020-02-29 18:39:00 +08:00
2020-02-29 18:38:56 +08:00
2020-03-01 19:33:18 +08:00

THIS PROJECT IS UNDER DEVELOPMENT, DON'T USE IT ON PRODUCTION ENVIRONMENT.

After the n0vad3v/webp_server, I decide to rewrite the whole program with Go, as there will be no more npm installs or docker-composes.

This is a Server based on Golang, which allows you to serve WebP images on the fly. It will convert jpg,jpeg,png files by default, this can be customized by editing the config.json..

e.g When you visit https://a.com/1.jpgit will serve as image/webp without changing the URL.

For Safari and Opera users, the original image will be used.

Compare to n0vad3v/webp_server

Size

  • webp_server with node_modules: 43M
  • webp-server(go) single binary: 15M

Performance

It's basically between ExpressJS and Fiber, much faster than the http package of course.

Convenience

  • webp_server: Clone the repo -> npm install -> run with pm2
  • webp-server(go): Download a single binary -> Run

General Usage Steps

Regarding the IMG_PATH section in config.json. If you are serving images at https://example.com/pics/tsuki.jpg and your files are at /var/www/image/pics/tsuki.jpg, then IMG_PATH shall be /var/www/image.

1. Download or build the binary

Download the webp-server from release page.

Wanna build your own binary? Check out build section

2. config file

Create a config.json as follows to face your need, default convert quality is 80%.

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

3. Run

Run the binary like this: ./webp-server --config /path/to/config.json, for prefetch mode, add --prefech.

Prefetch mode will pre-convert all the images in the IMG_PATH on initial start up.

screen or tmux

Use screen or tmux to avoid being terminated. Let's take screen for example

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

(Use Ctrl-A-D to detach the screen with webp-server running.)

systemd

Don't worry, we've got you covered!

Download webp-server to /opt/webps/webp-server, and create a config file to /opt/webps/config.json, then,

cp webps.service /lib/systemd/system/
systemctl daemon-reload
systemctl enable webps.service
systemctl start webps.service

4. Nginx proxy_pass

Let Nginx to proxy_pass http://localhost:3333/;, and your webp-server is on-the-fly

WordPress example

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

Build your own binaries

Install latest version of golang, enable go module, clone the repo, and then...

go build webp-server.go

Due to the limitations of webp module, you can't cross compile this tool. But the binary will work instantly on your platform and arch

TODO

  • This version doesn't support header-based-output, which means Safari users will not see the converted webp images, this should be fixed in later releases.
  • Multi platform support.
  • A better way to supervise the program.
  • Get rid of render-blocking effect on first render.
  • Prefetch on server initialization.
Description
重构二开版Go version of WebP Server. A tool that will serve your JPG/PNG/BMP/SVGs as WebP/AVIF format with compression, on-the-fly.
Readme GPL-3.0 32 MiB
Languages
Go 95.8%
Dockerfile 2.1%
Makefile 1.5%
Shell 0.6%