{"id":13747358,"url":"https://github.com/ksz2k/letter_avatar","last_synced_at":"2025-05-09T08:32:30.250Z","repository":{"id":20627826,"uuid":"23909468","full_name":"ksz2k/letter_avatar","owner":"ksz2k","description":"Ruby gem for creating letter avatar from user's name (or any other string :-) ).","archived":false,"fork":false,"pushed_at":"2021-09-06T15:32:51.000Z","size":176,"stargazers_count":271,"open_issues_count":1,"forks_count":48,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-05T01:11:57.198Z","etag":null,"topics":["letter-avatar","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ksz2k.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-11T07:59:14.000Z","updated_at":"2025-03-19T03:34:59.000Z","dependencies_parsed_at":"2022-08-28T20:52:15.700Z","dependency_job_id":null,"html_url":"https://github.com/ksz2k/letter_avatar","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksz2k%2Fletter_avatar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksz2k%2Fletter_avatar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksz2k%2Fletter_avatar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksz2k%2Fletter_avatar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ksz2k","download_url":"https://codeload.github.com/ksz2k/letter_avatar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253217148,"owners_count":21873021,"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":["letter-avatar","ruby"],"created_at":"2024-08-03T06:01:25.959Z","updated_at":"2025-05-09T08:32:29.929Z","avatar_url":"https://github.com/ksz2k.png","language":"Ruby","funding_links":[],"categories":["Ruby","Letter Avatar"],"sub_categories":[],"readme":"# LetterAvatar\n\nGem for creating letter avatar from user's name (or any other strong / character).\n\nCode extracted from [discourse](https://www.discourse.org/) source (thanks guys!) - I needed this functionality in three projects, so here's the gem! :-)\n\n[![Gem Version](https://badge.fury.io/rb/letter_avatar.svg)](https://badge.fury.io/rb/letter_avatar)\n[![Code Climate](https://codeclimate.com/github/ksz2k/letter_avatar/badges/gpa.svg)](https://codeclimate.com/github/ksz2k/letter_avatar)\n\n## Examples\n\n#### Google's Inbox Palette\n\n\u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031513/43eefa76-d30b-11e5-8f06-85f8eb2a4fb6.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031514/43ef6d8a-d30b-11e5-9fbc-38ae526b56b3.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031517/43f0da12-d30b-11e5-8fef-6c7daf235a54.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031515/43f0568c-d30b-11e5-95c5-1653361d4443.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031512/43eebcc8-d30b-11e5-9f95-0093bfadd182.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031516/43f0d0bc-d30b-11e5-8822-f01a6a138ff8.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031519/44382430-d30b-11e5-96e4-bcd7ce5eb155.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031518/44378d04-d30b-11e5-9400-55ff46b94cbe.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031521/443a03cc-d30b-11e5-8467-9592e9dbb2ae.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031523/443badc6-d30b-11e5-9d72-45613018cab4.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031520/44394e14-d30b-11e5-966c-2eada89295c9.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031522/443a71fe-d30b-11e5-88f4-37d1fd220abb.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031525/44752b1e-d30b-11e5-8290-ed8888055e64.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031524/4471cef6-d30b-11e5-9f4c-004f993dd27b.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031526/4475a990-d30b-11e5-8be3-c8f4482dee03.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031527/44772482-d30b-11e5-92f0-b9190c312d70.png\" width=\"60\" /\u003e \u003cimg src=\"https://cloud.githubusercontent.com/assets/5518/13031528/447804ce-d30b-11e5-8002-9424d5474ddb.png\" width=\"60\" /\u003e\n\n## Installation\n\nSystem requirements\n\n```bash\n$ sudo apt-get install -y imagemagick\n```\n\nMac OS X\n\n```bash\n$ brew install imagemagick ghostscript\n```\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'letter_avatar'\n```\n\nAnd then execute:\n\n```bash\n$ bundle\n```\n\nOr install it yourself as:\n\n```bash\n$ gem install letter_avatar\n```\n\n## Configuration\n\n```ruby\nLetterAvatar.setup do |config|\n  config.fill_color        = 'rgba(255, 255, 255, 1)' # default is 'rgba(255, 255, 255, 0.65)'\n  config.cache_base_path   = 'public/system/lets'     # default is 'public/system'\n  config.colors_palette    = :iwanthue                # default is :google\n  config.weight            = 500                      # default is 300\n  config.annotate_position = '-0+10'                  # default is -0+5\n  config.letters_count     = 2                        # default is 1\n  config.pointsize         = 70                       # default is 140\nend\n```\n\n#### Color palette\n\nWe have three color palettes implemented: `iwanthue`, `google` and `custom`.\n\nEach of them have different colors, but the `iwanthue` also differently calculates the color for specified username.\n\nThe `google` selected will generate the same avatar for both, \"Krzysiek\" and \"ksz2k\" usernames given (both of them starts with letter \"k\"), but `iwanthue` will calculate it's md5 and then selects color, so there's huge chance that these usernames get different colors.\n\n##### Custom palette definition\n\nYou can define your own `custom` palette:\n\n```ruby\nLetterAvatar.setup do |config|\n  config.colors_palette = :custom\n  config.custom_palette = [[120, 132, 205], [91, 149, 249], [72, 194, 249], [69, 208, 226]]\nend\n```\n\n##### Custom font definition\n\nYou can define your own `custom` palette:\n\n```ruby\nLetterAvatar.setup do |config|\n  config.font = File.join(File.expand_path('../../', File.dirname(__FILE__)), 'app/assets/fonts', 'font_name.ext')\nend\n```\n\n## Usage\n\n```ruby\nLetterAvatar.generate 'ksz2k', 200\n=\u003e \"public/system/letter_avatars/2/K/87_178_230/200.png\"\n```\n\n### In your controllers / views\n\nThere's also helper for this. To use it, you need:\n\n* in your helper (eg. `ApplicationHelper`) or controller:\n\n  ```ruby\n  include LetterAvatar::AvatarHelper\n  ```\n\n* and in your view:\n\n  ```ruby\n  letter_avatar_for('ksz2k', 200)\n  =\u003e \"public/system/letter_avatars/2/K/87_178_230/200.png\"\n  # or\n  letter_avatar_url('ksz2k', 200)\n  =\u003e \"/system/letter_avatars/2/K/87_178_230/200.png\"\n  # or even\n  letter_avatar_tag('ksz2k', 200, class: 'av')\n  =\u003e \"\u003cimg class=\\\"av\\\" alt=\\\"ksz2k\\\" src=\\\"/system/letter_avatars/2/K/87_178_230/200.png\\\" /\u003e\"\n  ```\n\n### In your model\n\nSay, you have a model `User` (which must have attribute or method `name`)\n\n```ruby\nrequire 'letter_avatar/has_avatar'\n\nclass User\n  include LetterAvatar::HasAvatar\n  ...\n\n  def name\n    'ksz2k'\n  end\nend\n```\n\nThen, in your views you can use:\n\n```ruby\n@user.avatar_path(200)\n=\u003e \"public/system/letter_avatars/2/K/87_178_230/200.png\"\n# or\n@user.avatar_url(200)\n=\u003e \"/system/letter_avatars/2/K/87_178_230/200.png\"\n```\n\n### Way to support non [a-z0-9] charsets\n\n```rb\nclass User\n  def username_for_avatar\n    # Translate Chinese hanzi to pinyin\n    # https://github.com/flyerhzm/chinese_pinyin\n    Pinyin.t(self.username)\n  end\nend\n```\n\nThen you can get right avatar now:\n\n```rb\nletter_avatar_for(user.username_for_avatar, 200)\n# or\nletter_avatar_tag(user.username_for_avatar, 200, class: 'av')\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksz2k%2Fletter_avatar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fksz2k%2Fletter_avatar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksz2k%2Fletter_avatar/lists"}