{"id":13694260,"url":"https://github.com/buckket/go-blurhash","last_synced_at":"2025-04-05T12:07:05.309Z","repository":{"id":41519410,"uuid":"185878791","full_name":"buckket/go-blurhash","owner":"buckket","description":"A Blurhash implementation in pure Go (Decode/Encode)","archived":false,"fork":false,"pushed_at":"2024-01-10T15:58:52.000Z","size":164,"stargazers_count":210,"open_issues_count":1,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T11:08:12.654Z","etag":null,"topics":["blurhash","go","golang","golang-library","mastodon"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/buckket.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":"buckket","issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-05-09T22:14:15.000Z","updated_at":"2025-03-23T13:41:31.000Z","dependencies_parsed_at":"2024-01-13T23:07:15.906Z","dependency_job_id":"1fc7e884-9857-4f49-90ee-1f31a6fa371f","html_url":"https://github.com/buckket/go-blurhash","commit_stats":{"total_commits":26,"total_committers":3,"mean_commits":8.666666666666666,"dds":0.1923076923076923,"last_synced_commit":"b97bf3be66e810606e1d08a69abe46608772b05e"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buckket%2Fgo-blurhash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buckket%2Fgo-blurhash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buckket%2Fgo-blurhash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buckket%2Fgo-blurhash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/buckket","download_url":"https://codeload.github.com/buckket/go-blurhash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332609,"owners_count":20921853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blurhash","go","golang","golang-library","mastodon"],"created_at":"2024-08-02T17:01:28.101Z","updated_at":"2025-04-05T12:07:05.229Z","avatar_url":"https://github.com/buckket.png","language":"Go","funding_links":["https://liberapay.com/buckket"],"categories":["开源类库","Open source library"],"sub_categories":["算法","Algorithm"],"readme":"# go-blurhash [![Build Status](https://travis-ci.org/buckket/go-blurhash.svg)](https://travis-ci.org/buckket/go-blurhash) [![Go Report Card](https://goreportcard.com/badge/github.com/buckket/go-blurhash)](https://goreportcard.com/report/github.com/buckket/go-blurhash) [![codecov](https://codecov.io/gh/buckket/go-blurhash/branch/master/graph/badge.svg)](https://codecov.io/gh/buckket/go-blurhash) [![GoDoc](https://godoc.org/github.com/buckket/go-blurhash?status.svg)](https://pkg.go.dev/github.com/buckket/go-blurhash)\n\n**go-blurhash** is a pure Go implementation of the [BlurHash](https://github.com/woltapp/blurhash) algorithm, which is used by\n[Mastodon](https://github.com/tootsuite/mastodon) an other Fediverse software to implement a swift way of preloading placeholder images as well\nas hiding sensitive media. Read more about it [here](https://blog.joinmastodon.org/2019/05/improving-support-for-adult-content-on-mastodon/).\n\n**tl;dr:** BlurHash is a compact representation of a placeholder for an image.\n\nThis library allows generating the BlurHash of a given image, as well as\nreconstructing a blurred version with specified dimensions from a given BlurHash.\n\nThis library is based on the following reference implementations:\n- Encoder: [https://github.com/woltapp/blurhash/blob/master/C](https://github.com/woltapp/blurhash/blob/master/C) (C)\n- Decoder: [https://github.com/woltapp/blurhash/blob/master/TypeScript](https://github.com/woltapp/blurhash/blob/master/TypeScript) (TypeScript)\n\nBlurHash is written by [Dag Ågren](https://github.com/DagAgren) / [Wolt](https://github.com/woltapp).\n\n|            | Before                         | After                          |\n| ---------- |:------------------------------:| :-----------------------------:|\n| **Image**  | ![alt text][test]              | \"LFE.@D9F01_2%L%MIVD*9Goe-;WB\" |\n| **Hash**   | \"LFE.@D9F01_2%L%MIVD*9Goe-;WB\" | ![alt text][test_blur]\n\n[test]: test.png \"Blurhash example input.\"\n[test_blur]: test_blur.png \"Blurhash example output\"\n\n## Installation\n\n### From source\n\n    go get -u github.com/buckket/go-blurhash\n\n## Usage\n\ngo-blurhash exports three functions:\n```go\nfunc blurhash.Encode(xComponents, yComponents int, rgba image.Image) (string, error)\nfunc blurhash.Decode(hash string, width, height, punch int) (image.Image, error)\nfunc blurhash.Components(hash string) (xComponents, yComponents int, err error)\n```\n\nHere’s a simple demonstration. Check [pkg.go.dev](https://pkg.go.dev/github.com/buckket/go-blurhash) for the full documentation.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/buckket/go-blurhash\"\n\t\"image/png\"\n\t\"os\"\n)\n\nfunc main() {\n\t// Generate the BlurHash for a given image\n\timageFile, _ := os.Open(\"test.png\")\n\tloadedImage, err := png.Decode(imageFile)\n\tstr, _ := blurhash.Encode(4, 3, loadedImage)\n\tif err != nil {\n\t\t// Handle errors\n\t}\n\tfmt.Printf(\"Hash: %s\\n\", str)\n\n\t// Generate an image for a given BlurHash\n\t// Width will be 300px and Height will be 500px\n\t// Punch specifies the contrasts and defaults to 1\n\timg, err := blurhash.Decode(str, 300, 500, 1)\n\tif err != nil {\n\t\t// Handle errors\n\t}\n\tf, _ := os.Create(\"test_blur.png\")\n\t_ = png.Encode(f, img)\n\t\n\t// Get the x and y components used for encoding a given BlurHash\n\tx, y, err := blurhash.Components(\"LFE.@D9F01_2%L%MIVD*9Goe-;WB\")\n\tif err != nil {\n\t\t// Handle errors\n\t}\n\tfmt.Printf(\"xComponents: %d, yComponents: %d\", x, y)\n}\n```\n\n## Limitations\n\n- Presumably a bit slower than the C implementation (TODO: Benchmarks)\n\n## Notes\n\n- As mentioned [here](https://github.com/woltapp/blurhash#how-fast-is-encoding-decoding), it’s best to\ngenerate very small images (~32x32px) via BlurHash and scale them up to the desired dimensions afterwards for optimal performance.\n- Since [#2](https://github.com/buckket/go-blurhash/pull/2) we diverted from the reference implementation by memorizing sRGBtoLinear values, thus increasing encoding speed at the cost of higher memory usage.\n- Starting with v1.1.0 the signature of blurhash.Encode() has changed slightly (see [#3](https://github.com/buckket/go-blurhash/issues/3)).\n\n## License\n\n GNU GPLv3+\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuckket%2Fgo-blurhash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuckket%2Fgo-blurhash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuckket%2Fgo-blurhash/lists"}