在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):buckket/go-blurhash开源软件地址(OpenSource Url):https://github.com/buckket/go-blurhash开源编程语言(OpenSource Language):Go 100.0%开源软件介绍(OpenSource Introduction):go-blurhashgo-blurhash is a pure Go implementation of the BlurHash algorithm, which is used by Mastodon an other Fediverse software to implement a swift way of preloading placeholder images as well as hiding sensitive media. Read more about it here. tl;dr: BlurHash is a compact representation of a placeholder for an image. This library allows generating the BlurHash of a given image, as well as reconstructing a blurred version with specified dimensions from a given BlurHash. This library is based on the following reference implementations:
BlurHash is written by Dag Ågren / Wolt.
InstallationFrom source
Usagego-blurhash exports three functions: func blurhash.Encode(xComponents, yComponents int, rgba image.Image) (string, error)
func blurhash.Decode(hash string, width, height, punch int) (image.Image, error)
func blurhash.Components(hash string) (xComponents, yComponents int, err error) Here’s a simple demonstration. Check pkg.go.dev for the full documentation. package main
import (
"fmt"
"github.com/buckket/go-blurhash"
"image/png"
"os"
)
func main() {
// Generate the BlurHash for a given image
imageFile, _ := os.Open("test.png")
loadedImage, err := png.Decode(imageFile)
str, _ := blurhash.Encode(4, 3, loadedImage)
if err != nil {
// Handle errors
}
fmt.Printf("Hash: %s\n", str)
// Generate an image for a given BlurHash
// Width will be 300px and Height will be 500px
// Punch specifies the contrasts and defaults to 1
img, err := blurhash.Decode(str, 300, 500, 1)
if err != nil {
// Handle errors
}
f, _ := os.Create("test_blur.png")
_ = png.Encode(f, img)
// Get the x and y components used for encoding a given BlurHash
x, y, err := blurhash.Components("LFE.@D9F01_2%L%MIVD*9Goe-;WB")
if err != nil {
// Handle errors
}
fmt.Printf("xComponents: %d, yComponents: %d", x, y)
} Limitations
Notes
LicenseGNU GPLv3+ |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论