{"id":15674825,"url":"https://github.com/renchap/shrine-blurhash","last_synced_at":"2025-05-06T20:43:50.931Z","repository":{"id":42684283,"uuid":"266878471","full_name":"renchap/shrine-blurhash","owner":"renchap","description":"Shrine plugin to compute Blurhash on image attachments","archived":false,"fork":false,"pushed_at":"2022-11-08T11:21:03.000Z","size":79,"stargazers_count":14,"open_issues_count":8,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-04T15:51:27.036Z","etag":null,"topics":["blurhash","shrine"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/renchap.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-25T20:56:00.000Z","updated_at":"2024-08-05T05:39:57.000Z","dependencies_parsed_at":"2023-01-22T12:00:09.588Z","dependency_job_id":null,"html_url":"https://github.com/renchap/shrine-blurhash","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renchap%2Fshrine-blurhash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renchap%2Fshrine-blurhash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renchap%2Fshrine-blurhash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/renchap%2Fshrine-blurhash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/renchap","download_url":"https://codeload.github.com/renchap/shrine-blurhash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252768988,"owners_count":21801373,"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","shrine"],"created_at":"2024-10-03T15:51:22.571Z","updated_at":"2025-05-06T20:43:50.907Z","avatar_url":"https://github.com/renchap.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Gem Version](https://badge.fury.io/rb/shrine-blurhash.svg)](https://badge.fury.io/rb/shrine-blurhash)\n\n# Shrine::Blurhash\n\nProvides [Blurhash] computing for [Shrine].\n\nMain features:\n- Multiple pixel extractors support. Current implementations:\n  - `ruby-vips`\n- Resize the image before computing blurhash (to 100 pixels by default) for a faster computation\n- Supports custom blurhash components parameter\n\n## Installation\n\nSimply add the gem to your `Gemfile`:\n\n```ruby\ngem \"shrine-blurhash\"\n```\n\nThen run `bundler`\n\n## Usage\n\nYou first need to load the plugin in your Uploader;\n\n```ruby\nclass PictureUploader \u003c Shrine\n  plugin :blurhash\nend\n```\n\nBlurhash will be now be computed when you upload a file and stored in a `blurhash` metadata, with a `.blurhash` method for quick access.\n\n## Options\n\nYou can pass options to the plugin to customize its behavior.\n\n```ruby\nclass PictureUploader \u003c Shrine\n  plugin :blurhash, resize_to: nil, components: [2, 2]\nend\n```\n\n### ```components```\n\nType: `[components_x, components_y]` or a `Proc`\nDefault: `[4, 3]`\n\n```ruby\nplugin :blurhash, components: [2, 2]\n```\n\nThis allows you to customize the number of components on each axis for the Blurhash algorithm. The visual result will look like a grid of `X * Y` blurred colors.\n\nYou can also pass a proc which receive the width and height and calculate the components on-the-fly:\n\n```ruby\nplugin :blurhash, components: -\u003e(width, height) { [width / 600, height / 600] }\n```\n\n### `resize_to`\n\nType: `Integer` or `nil`\nDefault: `100`\n\n```ruby\nplugin :blurhash, resize_to: 100\nplugin :blurhash, resize_to: nil\n```\n\nBefore computing the Blurhash for an image, this plugin needs to extract every pixel and store them in an array. This can result in a lot of memory allocations. To avoid using too much memory, this plugin resizes the image before extracting the pixels. This should not affect the visual result.\n\nYou can either specify the target size or `nil` to disable image resizing completely.\n\n### `extractor`\n\nType: `symbol` or `lambda`\n\n```ruby\nplugin :blurhash, extractor: :ruby_vips\n```\n\nSupported extractors:\n\n| Name           | Description                                                                                                                                   |\n| :-----------   | :-----------                                                                                                                                  |\n| `:ruby_vips`   | Uses the [ruby-vips] gem to extract pixels from File objects. If non-file IO object is given it will be temporarily downloaded to disk.   |\n\nYou can also create your own custom pixel extractor, where you can reuse\nany of the built-in analyzers. The analyzer is a lambda that accepts an IO\nobject and returns a `[width, height, pixels]` array containing image width, image height and all the pixels in the images in an array, or `nil` if pixels could not be extracted.\n\n### `auto_extraction`\n\nType: `boolean`\n\n- Multiple pixel extractors support, even if only VIPS is implemented right now\n- Allows to resize the image before computing blurhash (to 100 pixels by default) for a faster computation\n- Supports custom blurhash components parameter\n\n## Errors\n\nBy default, any exceptions that the plugin raises while computing blurhash\nwill be caught and a warning will be printed out. This allows you to have the\nplugin loaded even for files that are not images.\n\nHowever, you can choose different strategies for handling these exceptions:\n\n```rb\nplugin :blurhash, on_error: :warn        # prints a warning (default)\nplugin :blurhash, on_error: :fail        # raises the exception\nplugin :blurhash, on_error: :ignore      # ignores exceptions\nplugin :blurhash, on_error: -\u003e (error) { # custom handler\n  # report the exception to your exception handler\n}\n```\n\n## Contributing\n\n### Running tests\n\nAfter setting up your bucket, run the tests:\n\n```sh\n$ bundle exec rake test\n```\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT)\n\n[Shrine]: https://github.com/shrinerb/shrine\n[Blurhash]: https://blurha.sh\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenchap%2Fshrine-blurhash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frenchap%2Fshrine-blurhash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frenchap%2Fshrine-blurhash/lists"}