blurhash

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2025 License: MIT-0 Imports: 10 Imported by: 0

README

Go URL Blurhash

🦄 Simple Go utility to generate blurhash from Image URL or local file

Go Version License

📦 Requirements
  • Go 1.19 or higher
✨ Installation
go get github.com/mcnaveen/go-url-blurhash
💡 Usage Example
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)
}
✅ Example Output
{
    "Encoded": "UnR.*,kW.TnPt7WBocozpJV@nMkWadofWCV@",
    "Width": 600,
    "Height": 600
}
Optional Parameters

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
}

💚 Message

I hope you find this useful. If you have any questions, please create an issue.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Size    int
	Offline bool
}

type Output

type Output struct {
	Encoded string
	Width   int
	Height  int
}

func BlurhashFromURL

func BlurhashFromURL(source string, options Options) (Output, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址