# webp_server_go **Repository Path**: teng2015/webp_server_go ## Basic Information - **Project Name**: webp_server_go - **Description**: No description available - **Primary Language**: Go - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2022-03-17 - **Last Updated**: 2022-03-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 这是原作者的文档,基本一致 [Documentation](https://docs.webp.sh/) | [Website](https://webp.sh/) 基于 golang 语言的动态将图片缩小 和 转 webp 的服务 默认转换`jpg,jpeg,png,gif`类型文件为 webp,可以通过`config.json`参数指定转换的文件类型 - JPEG, PNG, BMP, GIF 格式的图片可转为 webp 格式 - JPEG, PNG, BMP 格式支持缩放,gif 缩放太慢所以不支持 - 对于不支持 webp 格式的浏览器,发送原图格式 ## 使用步骤 ### 下载并构建二进制文件 [https://gitee.com/adtk/webp_server_go](https://gitee.com/adtk/webp_server_go) ### 构建 ``` go build . ``` ### 运行 ```sh ./webp_server_go # or ./webp_server_go --config=/path/to/config.json ``` ```json // config.json { "HOST": "127.0.0.1", "PORT": "3333", "QUALITY": "80", //压缩质量 0-100 默认80 "IMG_PATH": "/path/to/pics", // 图片存放目录 "EXHAUST_PATH": "/path/to/exhaust", // 图片缩小转换后存放目录 "ALLOWED_TYPES": ["jpg", "png", "jpeg", "bmp", "gif"] } ``` # 本仓库改进点 1. 去掉了 avif 的支持,因为 avif 的支持使得打包复杂,浏览器支持度也不够 2. 根据请求参数进行缩放图片 ```go // http://127.0.0.1:3333/png.jpg?m=lfit&w=200&h=200&q=100 type Resize struct { Mode string `query:"m" json:"m,int"` // mode, lfit等比缩放 Width uint `query:"w" json:"w"` // width 最大宽度,图片宽度超过这个值,则不变,默认不变 Height uint `query:"h" json:"h"` // height 最大高度,图片高度超过这个值,则不变,默认不变 Quality uint `query:"q" json:"q"` // quality 图片质量0-100,默认80 } ``` ## 缺点 1. 目前仅支持一个 IMG_PATH 目录,后续看考虑多目录,原作者建议是创建软连接 ## Nginx 配置代理 proxy_pass Let Nginx to `proxy_pass http://localhost:3333/;`, and your webp-server is on-the-fly. ## 更多文档请参考原作者文档 [https://docs.webp.sh/](https://docs.webp.sh/) ## License WebP Server is under the GPLv3. See the [LICENSE](./LICENSE) file for details.