🦄 Simple Go utility to generate blurhash from Image URL or local file
- Go 1.19 or higher
go get github.com/mcnaveen/go-url-blurhash
package main
import (
"fmt"
"github.com/mcnaveen/go-url-blurhash/blurhash"
)
func main() {
// Generate blurhash from URL
output, err := blurhash.BlurhashFromURL("https://i.imgur.com/NhfEdg2.png", blurhash.Options{
Size: 32, // Optional, defaults to 32
})
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", output)
// Generate blurhash from local file
localOutput, err := blurhash.BlurhashFromURL("./image.jpg", blurhash.Options{
Size: 32,
Offline: true,
})
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", localOutput)
}
{
"Encoded": "UnR.*,kW.TnPt7WBocozpJV@nMkWadofWCV@",
"Width": 600,
"Height": 600
}
The Options
struct accepts the following parameters:
Size
: Image resize dimensions (default: 32)Offline
: Boolean to process local files instead of URLs (default: false)
options := blurhash.Options{
Size: 64, // Optional: Custom size
Offline: true, // Optional: Process local files
}
I hope you find this useful. If you have any questions, please create an issue.