WebP Server Go 0.13.0 is released
We believe that open-source software is the foundation of freedom. While we are working hard to promote our SaaS products WebP Cloud and Public Services, we are also continuously improving our open-source software versions to provide users with more choices.
What is WebP Server Go
WebP Server Go is an open-source program licensed under the GPLv3 (at least for now), with the code hosted at https://github.com/webp-sh/webp_server_go.
It aims to dynamically optimize/compress original images into more modern formats without changing the original URLs. This helps solve the issue of websites serving large older format images (such as JPG, PNG), which can lead to extra server bandwidth costs and slow loading speeds. Consequently, it improves webpage response speed and PageSpeed scores.
Assume you have a website: https://example.com with many images and photos at https://example.com/pics/someimages.jpg, with sizes ranging from 1M to 5M. Directly placing these images on the webpage would result in very slow loading times. Using WebP Server Go can achieve the following:
- Keep the original image URLs unchanged.
- Reduce the image size and output them in more modern formats (e.g.,
webp
,avif
). - Convert images to formats supported by the browser (e.g., if the original image is in
avif
format but the visitor’s browser does not supportavif
, WebP Server will convert the image towebp
format for the visitor).
The advantages of WebP Server Go include:
- No need to manually process all images on the website in advance, which is time-consuming and laborious.
- No need to change image URLs; the image URLs in the address can still end with
.jpg
, but the output will be inwebp
oravif
format. - Due to browser limitations for formats like
webp
andavif
(e.g., Firefox versions 77-92 do not supportavif
), WebP Server Go will automatically output an image in the smallest possible size that the browser can accept.
How to Use WebP Server Go
To help everyone understand the role of WebP Server Go more intuitively, let’s look at a very simple use case. All my images are stored in the /path/to/pics
directory, and I want a simple HTTP service that outputs optimized images upon access.
The simplest way currently is to deploy directly using Docker containers. We just need to mount three directories into the container. Create a docker-compose.yml
file and write the following content:
version: '3'
services:
webp:
image: webpsh/webp-server-go
restart: always
volumes:
- /path/to/pics:/opt/pics
- ./exhaust:/opt/exhaust
- ./metadata:/opt/metadata
ports:
- 127.0.0.1:3333:3333
Here, /path/to/pics
is the directory where our images are stored. The remaining ./exhaust
and ./metadata
are the directories for storing optimized images and source information, respectively. For convenience, they are placed in the same directory as docker-compose.yml
.
Then start it with docker-compose up -d
. At this point, the WebP Server is already running on http://127.0.0.1:3333
.
Suppose our actual image is /path/to/pics/DSC05955.jpg
, we can access http://127.0.0.1:3333/DSC05955.jpg
to see the optimized image.
- Content-Type: image/webp indicates the image has been output in
webp
format. - X-Compression-Rate: 0.13 indicates the current image size is 13% of the original.
How about that? Simple and easy to understand. Next, just wrap it with a web server like Nginx/Caddy to use it externally.
More configuration/deployment information can be found in the documentation we maintain at https://docs.webp.sh/.
New Features
Let’s take a look at the new features introduced in version 0.13.0!
Direct Output of Non-Image Files
We have seen many users requesting direct output of non-image files:
- https://github.com/webp-sh/webp_server_go/issues/322
- https://github.com/webp-sh/webp_server_go/issues/267
- https://github.com/webp-sh/webp_server_go/issues/25
- https://github.com/webp-sh/webp_server_go/issues/351
Starting from version 0.13.0, if your configuration file sets ALLOWED_TYPES
to *, like this:
"ALLOWED_TYPES": ["*"],
WebP Server Go can directly output non-image files.
We determine whether a file is an image based on its file extension. We consider the following extensions as images:
"jpg", "png", "jpeg", "bmp", "gif", "svg", "nef", "heic", "webp", "avif", "jxl"
.
For example:
curl -H "Accept: image/webp" http://localhost:3333/config.json
{
"HOST": "0.0.0.0",
"PORT": "3333",
"QUALITY": "80",
"IMG_PATH": "./pics",
"EXHAUST_PATH": "./exhaust",
"ALLOWED_TYPES": [
"*"
],
"CONVERT_TYPES": ["webp","avif","jxl"],
"ENABLE_EXTRA_PARAMS": true,
"MAX_CACHE_SIZE": 5
}%
Reverse Conversion
Before version 0.13.0, our goal was to act as a bridge from older image formats (e.g., JPG, PNG) to newer image formats (e.g., WebP and AVIF). We always assumed that the user’s original images were in older formats and would directly output the original images if the browser did not support the newer formats.
However, this posed a problem: what if the user’s original image was in AVIF format, but the visitor’s browser did not support AVIF?
Before version 0.13.0, WebP Server would directly output the original AVIF image, causing users to see no image at all, as mentioned in Issue https://github.com/webp-sh/webp_server_go/issues/369.
Starting from version 0.13.0, we will treat all images independently, without simply distinguishing between older and newer formats. For example, if your original image is in AVIF format but the browser only supports WebP format, we will output the image in WebP format to the browser:
curl -I -H "Accept: image/webp" http://localhost:3333/k.avif
HTTP/1.1 200 OK
Server: WebP Server Go
Date: Sat, 11 Jan 2025 04:00:31 GMT
Content-Type: image/webp
Content-Length: 106524
X-Compression-Rate: 1.25
Accept-Ranges: bytes
Last-Modified: Sat, 11 Jan 2025 04:00:25 GMT
The same logic applies to HEIC images:
curl -I -H "Accept: image/webp,image/apng,image/*,*/*;q=0.8" http://localhost:3333/sample3.heic
HTTP/1.1 200 OK
Server: WebP Server Go
Date: Sat, 11 Jan 2025 04:03:26 GMT
Content-Type: image/webp
Content-Length: 603808
X-Compression-Rate: 1.12
Accept-Ranges: bytes
Last-Modified: Sun, 29 Dec 2024 04:01:30 GMT
Considering that the WebP format is already supported by the vast majority of browsers, we will maintain the output of the original image for clients that do not support the WebP format (e.g., cURL
), rather than further converting it to PNG/JPG formats.
Metadata
Two months ago, we introduced the Metadata feature on WebP Cloud. The related article is “Better Preview Experience! WebP Cloud Supports Metadata Requests with Blurhash”.
In this version, we have brought the Metadata feature to WebP Server Go as well. Similar to WebP Cloud, you can obtain the Metadata information of an original image by adding ?meta=full
to the request, for example:
curl -H "Accept: image/png" http://localhost:3333/DSC05953.jpg\?meta\=full
{"blurhash":"LrF~8PIUWBfk~VM{WBaz-pWBRjay","colorspace":"sRGB","format":"jpeg","height":3375,"num_pages":1,"size":60750000,"width":6000}
Bugfix & Optimize
In addition to the new features mentioned above, we have also made some minor fixes and optimizations, such as:
ALLOWED_TYPES
not using deep copy, causing the configuration file and the actual loaded configuration to be overwritten (https://github.com/webp-sh/webp_server_go/issues/369#issuecomment-2551614864)- We have fixed this bug.
- For original images in WebP format, WebP Server would convert them again to WebP/AVIF formats.
- In such cases, we will directly copy the original image to the target directory, reducing conversion computational costs.
We hope you enjoy this version. If you encounter any issues or have new ideas, feel free to submit an issue at Issues · webp-sh/webp_server_go!
The WebP Cloud Services team is a small team of three individuals from Shanghai and Helsingborg. Since we are not funded and have no profit pressure, we remain committed to doing what we believe is right. We strive to do our best within the scope of our resources and capabilities. We also engage in various activities without affecting the services we provide to the public, and we continuously explore novel ideas in our products.
If you find this service interesting, feel free to log in to the WebP Cloud Dashboard to experience it. If you’re curious about other magical features it offers, take a look at our WebP Cloud Services Docs. We hope everyone enjoys using it!
Discuss on Hacker News