{"id":15639013,"url":"https://github.com/halcy/blurhash-python","last_synced_at":"2025-04-05T03:09:03.890Z","repository":{"id":41258195,"uuid":"185877472","full_name":"halcy/blurhash-python","owner":"halcy","description":"Implementation of the blurhash ( https://github.com/woltapp/blurhash ) algorithm in pure python","archived":false,"fork":false,"pushed_at":"2020-08-10T22:47:19.000Z","size":78,"stargazers_count":92,"open_issues_count":1,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T02:05:11.438Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","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/halcy.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}},"created_at":"2019-05-09T22:00:59.000Z","updated_at":"2025-03-07T19:50:04.000Z","dependencies_parsed_at":"2022-09-01T18:22:53.779Z","dependency_job_id":null,"html_url":"https://github.com/halcy/blurhash-python","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/halcy%2Fblurhash-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halcy%2Fblurhash-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halcy%2Fblurhash-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halcy%2Fblurhash-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/halcy","download_url":"https://codeload.github.com/halcy/blurhash-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247280272,"owners_count":20912967,"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":"2024-10-03T11:24:20.625Z","updated_at":"2025-04-05T03:09:03.870Z","avatar_url":"https://github.com/halcy.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# blurhash-python\n```python\nimport blurhash\nimport PIL.Image\nimport numpy\n\nPIL.Image.open(\"cool_cat_small.jpg\")\n# Result:\n```\n![A picture of a cool cat.](/cool_cat_small.jpg?raw=true \"A cool cat.\")\n```python\nblurhash.encode(numpy.array(PIL.Image.open(\"cool_cat_small.jpg\").convert(\"RGB\")))\n# Result: 'UBL_:rOpGG-oBUNG,qRj2so|=eE1w^n4S5NH'\n\nPIL.Image.fromarray(numpy.array(blurhash.decode('UBL_:rOpGG-oBUNG,qRj2so|=eE1w^n4S5NH', 128, 128)).astype('uint8'))\n# Result:\n```\n![Blurhash example output: A blurred cool cat.](/blurhash_example.png?raw=true \"Blurhash example output: A blurred cool cat.\")\n    \nBlurhash is an algorithm that lets you transform image data into a small text representation of a blurred version of the image. This is useful since this small textual representation can be included when sending objects that may have images attached around, which then can be used to quickly create a placeholder for images that are still loading or that should be hidden behind a content warning.\n\nThis library contains a pure-python implementation of the blurhash algorithm, closely following the original swift implementation by Dag Ågren. The module has no dependencies (the unit tests require PIL and numpy). You can install it via pip:\n\n```bash\n$ pip3 install blurhash\n```\n\nIt exports five functions:\n* \"encode\" and \"decode\" do the actual en- and decoding of blurhash strings\n* \"components\" returns the number of components x- and y components of a blurhash\n* \"srgb_to_linear\" and \"linear_to_srgb\" are colour space conversion helpers\n\nHave a look at example.py for an example of how to use all of these working together.\n\nDocumentation for each function:\n\n```python\nblurhash.encode(image, components_x = 4, components_y = 4, linear = False):\n\"\"\"\nCalculates the blurhash for an image using the given x and y component counts.\n\nImage should be a 3-dimensional array, with the first dimension being y, the second\nbeing x, and the third being the three rgb components that are assumed to be 0-255 \nsrgb integers (incidentally, this is the format you will get from a PIL RGB image).\n\nYou can also pass in already linear data - to do this, set linear to True. This is\nuseful if you want to encode a version of your image resized to a smaller size (which\nyou should ideally do in linear colour).\n\"\"\"\n\nblurhash.decode(blurhash, width, height, punch = 1.0, linear = False)\n\"\"\"\nDecodes the given blurhash to an image of the specified size.\n    \nReturns the resulting image a list of lists of 3-value sRGB 8 bit integer\nlists. Set linear to True if you would prefer to get linear floating point \nRGB back.\n\nThe punch parameter can be used to de- or increase the contrast of the\nresulting image.\n\nAs per the original implementation it is suggested to only decode\nto a relatively small size and then scale the result up, as it\nbasically looks the same anyways.\n\"\"\"\n\nblurhash.srgb_to_linear(value):\n\"\"\"\nsrgb 0-255 integer to linear 0.0-1.0 floating point conversion.\n\"\"\"\n    \nblurhash.linear_to_srgb(value):\n\"\"\"\nlinear 0.0-1.0 floating point to srgb 0-255 integer conversion.\n\"\"\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalcy%2Fblurhash-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhalcy%2Fblurhash-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalcy%2Fblurhash-python/lists"}