{"id":24986942,"url":"https://github.com/rinpatch/blurhash","last_synced_at":"2025-04-11T23:30:24.631Z","repository":{"id":57544142,"uuid":"377774874","full_name":"rinpatch/blurhash","owner":"rinpatch","description":"A pure Elixir implementation Blurhash decoder/encoder.","archived":false,"fork":false,"pushed_at":"2024-08-16T14:08:54.000Z","size":12,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T19:21:13.613Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rinpatch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-17T09:26:14.000Z","updated_at":"2024-10-10T04:37:03.000Z","dependencies_parsed_at":"2025-02-04T11:34:22.877Z","dependency_job_id":"2f8c25ad-072f-4fd8-9f35-98c0e0285a26","html_url":"https://github.com/rinpatch/blurhash","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rinpatch%2Fblurhash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rinpatch%2Fblurhash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rinpatch%2Fblurhash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rinpatch%2Fblurhash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rinpatch","download_url":"https://codeload.github.com/rinpatch/blurhash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247847614,"owners_count":21006100,"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":[],"created_at":"2025-02-04T11:34:05.039Z","updated_at":"2025-04-11T23:30:24.603Z","avatar_url":"https://github.com/rinpatch.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Blurhash\n\nA pure Elixir implementation [Blurhash](https://blurha.sh/) decoder/encoder.\n\nDocumentation: \u003chttps://hexdocs.pm/rinpatch_blurhash\u003e\n\n## Installation\n\nAdd Blurhash to your `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:blurhash, \"~\u003e 0.1.0\", hex: :rinpatch_blurhash}\n  ]\nend\n```\n\nIf you would like to use the `downscale_and_decode/3` function, you also need to add `Mogrify`:\n\n```elixir\ndef deps do\n  [\n    {:blurhash, \"~\u003e 0.1.0\", hex: :rinpatch_blurhash},\n    {:mogrify, \"~\u003e 0.8.0\"}\n  ]\nend\n```\n\n## Usage\n\n### Encoding\n\nThe algorithm authors recommend to downscale the image to 32-20 pixels in width before encoding the blurhash, this will make encoding faster while leading to a similar-looking result. If ImageMagick is available on your system, you can simply add `Mogrify` package to your dependencies and use `downscale_and_encode/3`:\n```elixir\npath = \"/tmp/lenna.png\"\ncomponents_x = 4\ncomponents_y = 3\n\n{:ok, blurhash} = Blurhash.downscale_and_encode(path, components_x, components_y)\n```\n**Be aware that this function uses a port and has no rate limiting or pooling. If a large number of blurhashes needs to be encoded at the same time, use an external solution to limit it, such as a job queue.**\n\nIf you already have a thumbnail to encode to a blurhash, the `encode/5` function accepts a raw 8-bit RGB binary along with it's width and height.\n\nHere is how to convert an image to raw pixels using imagemagick:\n```sh\nconvert lenna.png -depth 8 lenna.rgb\n```\n\nThen you can use it like this:\n```elixir\nlenna = File.read!(\"lenna.rgb\")\nwidth = 512\nheight = 512\ncomponents_x = 4\ncomponents_y = 3\n\n{:ok, blurhash} = Blurhash.encode(lenna, width, height, 4, 3)\n```\n\n### Decoding\n\nThe `decode/3` functions accepts a blurhash, as well as the width and height of the result image. The output is 8-bit raw RGB binary and the average colour of the image as an `{r, g, b}` tuple.\n\nFor example, decoding a blurhash to a 32x32 image:\n```elixir\nblurhash = \"LELxMqDQNE}@^5=aR6N^v}ozEh-n\"\nwidth = 32\nheight = 32\n\n{:ok, pixels, {r, g, b} = average_color} = Blurhash.decode(blurhash, width, height)\n```\n\n`decode_to_iodata/3` function is the same as `decode/3`, except it returns iodata instead of a binary. This is useful if you are writing the raw pixels to a file or a socket later.\n\nFor example, decoding a blurhash, writing the raw pixels to a file and converting it to a jpg using `Mogrify`:\n```elixir\nblurhash = \"LELxMqDQNE}@^5=aR6N^v}ozEh-n\"\nwidth = 32\nheight = 32\n\n{:ok, pixels_iodata, {r, g, b} = average_color} = Blurhash.decode(blurhash, width, height)\n\ndecoded_raw_path = \"lenna_blurhash.rgb\"\nFile.write!(decoded_raw_path, pixels_iodata)\n\n%{path: decoded_jpg_path} = \n  Mogrify.open(decoded_raw_path) |\u003e Mogrify.custom(\"size\", \"#{width}x#{height}\") |\u003e Mogrify.custom(\"depth\", \"8\")|\u003e Mogrify.format(\"jpg\") |\u003e Mogrify.save()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frinpatch%2Fblurhash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frinpatch%2Fblurhash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frinpatch%2Fblurhash/lists"}