增加dht的去中心化储存

This commit is contained in:
2025-10-21 15:29:43 +08:00
parent 248f9a28e7
commit ab2f099826
14 changed files with 517 additions and 87 deletions

50
build/ico/main.go Normal file
View File

@@ -0,0 +1,50 @@
package main
import (
"image"
"os"
"github.com/icza/icox" // 替换为icox库
"github.com/nfnt/resize"
)
func main() {
// 1. 读取PNG文件
inputPath := "manifest/images/logo.png" // 输入PNG路径
outputPath := "manifest/images/favicon.ico" // 输出ICO路径
pngFile, err := os.Open(inputPath)
if err != nil {
panic("无法打开PNG文件: " + err.Error())
}
defer pngFile.Close()
// 2. 解码PNG为image.Image对象
img, _, err := image.Decode(pngFile)
if err != nil {
panic("PNG解码失败: " + err.Error())
}
// 3. 定义ICO需要包含的尺寸常见尺寸
sizes := []uint{16, 32, 64, 128} // 可根据需求添加更多尺寸
var icoImages []image.Image
// 4. 缩放图像到每个目标尺寸并收集
for _, size := range sizes {
// 使用Lanczos3算法缩放高质量
resized := resize.Resize(size, size, img, resize.Lanczos3)
icoImages = append(icoImages, resized)
}
// 5. 编码为ICO并写入文件关键修改使用icox.Encode
icoFile, err := os.Create(outputPath)
if err != nil {
panic("无法创建ICO文件: " + err.Error())
}
defer icoFile.Close()
// icox.Encode直接支持多尺寸切片[]image.Image
if err := icox.Encode(icoFile, icoImages); err != nil {
panic("ICO编码失败: " + err.Error())
}
}