All Projects → buckket → Go Blurhash

buckket / Go Blurhash

Licence: gpl-3.0
A Blurhash implementation in pure Go (Decode/Encode)

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Go Blurhash

Mastodon
Your self-hosted, globally interconnected microblogging community
Stars: ✭ 26,120 (+22613.04%)
Mutual labels:  mastodon
Mastodon Bridge
Moved to https://source.joinmastodon.org/mastodon/bridge
Stars: ✭ 53 (-53.91%)
Mutual labels:  mastodon
Microstatus
Lightweight Mastodon- and GNU social-compatible ActivityPub and OStatus server implementation
Stars: ✭ 96 (-16.52%)
Mutual labels:  mastodon
Toot Relay
Relay that forwards web push notifications to APNs, built for Toot!.app but usable for anyone.
Stars: ✭ 18 (-84.35%)
Mutual labels:  mastodon
Ananas
The Python Bot Framework for Mastodon
Stars: ✭ 46 (-60%)
Mutual labels:  mastodon
Indigenous Android
An open social app with support for IndieWeb, Mastodon, Pleroma and Pixelfed.
Stars: ✭ 69 (-40%)
Mutual labels:  mastodon
Whalebird Desktop
An Electron based Mastodon, Pleroma and Misskey client for Windows, Mac and Linux
Stars: ✭ 517 (+349.57%)
Mutual labels:  mastodon
Forget
Continuous post deletion for twitter and mastodon
Stars: ✭ 104 (-9.57%)
Mutual labels:  mastodon
Megalodon
Mastodon, Pleroma and Misskey API client library for node.js and browser
Stars: ✭ 52 (-54.78%)
Mutual labels:  mastodon
Mastodon Api
Mastodon API Client Library
Stars: ✭ 89 (-22.61%)
Mutual labels:  mastodon
Orion
🚀 "Orion" is generic fediverse microblogging application for Desktop.
Stars: ✭ 14 (-87.83%)
Mutual labels:  mastodon
Ocrbot
An OCR (Optical Character Recognition) bot for Mastodon (and compatible) instances
Stars: ✭ 39 (-66.09%)
Mutual labels:  mastodon
Tooter
Add 'Toot' and 'Share to Mastodon' buttons to the web
Stars: ✭ 75 (-34.78%)
Mutual labels:  mastodon
Fed.ialis.me
a guide to the fediverse -- WIP
Stars: ✭ 17 (-85.22%)
Mutual labels:  mastodon
Naumanni
Naumanni is a Web user interface specially designed for Mastodon.
Stars: ✭ 97 (-15.65%)
Mutual labels:  mastodon
Pinafore
Alternative web client for Mastodon
Stars: ✭ 556 (+383.48%)
Mutual labels:  mastodon
Tusky
An Android client for the microblogging server Mastodon
Stars: ✭ 1,070 (+830.43%)
Mutual labels:  mastodon
Documentation
Full documentation repository for Mastodon
Stars: ✭ 1,450 (+1160.87%)
Mutual labels:  mastodon
The Federation.info
Statistics hub for the Fediverse
Stars: ✭ 101 (-12.17%)
Mutual labels:  mastodon
Sharexin
ShareX for Linux and BSD
Stars: ✭ 79 (-31.3%)
Mutual labels:  mastodon

go-blurhash Build Status Go Report Card codecov GoDoc

go-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.

Before After
Image alt text "[email protected]_2%L%MIVD*9Goe-;WB"
Hash "[email protected]_2%L%MIVD*9Goe-;WB" alt text

Installation

From source

go get -u github.com/buckket/go-blurhash

Usage

go-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("[email protected]_2%L%MIVD*9Goe-;WB")
	if err != nil {
		// Handle errors
	}
	fmt.Printf("xComponents: %d, yComponents: %d", x, y)
}

Limitations

  • Presumably a bit slower than the C implementation (TODO: Benchmarks)

Notes

  • As mentioned here, it’s best to generate very small images (~32x32px) via BlurHash and scale them up to the desired dimensions afterwards for optimal performance.
  • Since #2 we diverted from the reference implementation by memorizing sRGBtoLinear values, thus increasing encoding speed at the cost of higher memory usage.
  • Starting with v1.1.0 the signature of blurhash.Encode() has changed slightly (see #3).

License

GNU GPLv3+

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].