-
Notifications
You must be signed in to change notification settings - Fork 30
Make a default avatar with transparent background and adaptive coloring based on username #1357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 39 commits
f9e96fb
df9b624
76747e7
5b71cee
6589998
3bf8446
e5579c8
143015f
8f10a63
3f91bea
011fd72
e1f9ff6
9f0c8e9
f1ce464
690c725
20031e2
ccfde0e
b0ccc95
98e0f31
128651c
619fbbc
584a9b8
39ee1ed
b272cfd
05bf0f4
c76fb3e
d3a9c00
4463ed3
4d8e354
456d96a
af9089a
5ced290
e9028ff
93b2c87
3af659e
f609a93
5533144
aabc057
674bda3
76f2f84
71ab2db
4c8706d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "CurrentProjectSetting": null | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "ExpandedNodes": [ | ||
| "", | ||
| "\\templates\\components" | ||
| ], | ||
| "SelectedNode": "\\templates", | ||
| "PreviewInSolutionExplorer": false | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| { | ||
| "Version": 1, | ||
| "WorkspaceRootPath": "C:\\Users\\Michael\\source\\repos\\mbin\\", | ||
| "Documents": [ | ||
| { | ||
| "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\Michael\\source\\repos\\mbin\\templates\\components\\user_avatar.html.twig||{8B382828-6202-11D1-8870-0000F87579D2}", | ||
| "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:templates\\components\\user_avatar.html.twig||{8B382828-6202-11D1-8870-0000F87579D2}" | ||
| }, | ||
| { | ||
| "AbsoluteMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|C:\\Users\\Michael\\source\\repos\\mbin\\templates\\components\\user_inline.html.twig||{FA3CD31E-987B-443A-9B81-186104E8DAC1}", | ||
| "RelativeMoniker": "D:0:0:{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}|\u003CMiscFiles\u003E|solutionrelative:templates\\components\\user_inline.html.twig||{FA3CD31E-987B-443A-9B81-186104E8DAC1}" | ||
| } | ||
| ], | ||
| "DocumentGroupContainers": [ | ||
| { | ||
| "Orientation": 0, | ||
| "VerticalTabListWidth": 256, | ||
| "DocumentGroups": [ | ||
| { | ||
| "DockedWidth": 200, | ||
| "SelectedChildIndex": 1, | ||
| "Children": [ | ||
| { | ||
| "$type": "Bookmark", | ||
| "Name": "ST:128:0:{116d2292-e37d-41cd-a077-ebacac4c8cc4}" | ||
| }, | ||
| { | ||
| "$type": "Document", | ||
| "DocumentIndex": 0, | ||
| "Title": "user_avatar.html.twig", | ||
| "DocumentMoniker": "C:\\Users\\Michael\\source\\repos\\mbin\\templates\\components\\user_avatar.html.twig", | ||
| "RelativeDocumentMoniker": "templates\\components\\user_avatar.html.twig", | ||
| "ToolTip": "C:\\Users\\Michael\\source\\repos\\mbin\\templates\\components\\user_avatar.html.twig", | ||
| "RelativeToolTip": "templates\\components\\user_avatar.html.twig", | ||
| "ViewState": "AgIAAA8AAAAAAAAAAAAAAC8AAAAEAAAAAAAAAA==", | ||
| "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001001|", | ||
| "WhenOpened": "2025-03-14T17:27:49.905Z", | ||
| "EditorCaption": "" | ||
| }, | ||
| { | ||
| "$type": "Bookmark", | ||
| "Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}" | ||
| }, | ||
| { | ||
| "$type": "Document", | ||
| "DocumentIndex": 1, | ||
| "Title": "user_inline.html.twig", | ||
| "DocumentMoniker": "C:\\Users\\Michael\\source\\repos\\mbin\\templates\\components\\user_inline.html.twig", | ||
| "RelativeDocumentMoniker": "templates\\components\\user_inline.html.twig", | ||
| "ToolTip": "C:\\Users\\Michael\\source\\repos\\mbin\\templates\\components\\user_inline.html.twig", | ||
| "RelativeToolTip": "templates\\components\\user_inline.html.twig", | ||
| "ViewState": "AgIAAAcAAAAAAAAAAAAAwBAAAAAhAAAAAAAAAA==", | ||
| "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.001001|", | ||
| "WhenOpened": "2025-03-14T14:48:57.898Z", | ||
| "EditorCaption": "" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this image looks like it is created in Ms Paint? The borders are very pixelated. You do know that we have very quality infinitely sharp SVG files? https://github.com/MbinOrg/mbin/blob/main/assets/images/sources/mbin-notext.svg These can be opened in Inkscape. edited and then exported to PNG if you wish to use png.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my response below. I did all the work for you already now. You can just take that SVG content and only modify the style in the |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,53 @@ | ||
| <figure{{ attributes }}> | ||
| {% if asLink %} | ||
| <a data-action="mouseover->mentions#user_popup mouseout->mentions#user_popup_out" data-mentions-username-param="{{ mention_url(user.username) }}" | ||
| href="{{ path('user_overview', {username: user.username}) }}"> | ||
| {% endif %} | ||
| {% if user.avatar %} | ||
| <img class="image-inline" | ||
| loading="lazy" | ||
| width="{{ width }}" height="{{ height }}" | ||
| style="max-width: {{ width }}px; max-height: {{ height }}px;" | ||
| src="{{ user.avatar.filePath ? (asset(user.avatar.filePath)|imagine_filter('avatar_thumb')) : user.avatar.sourceUrl }}" | ||
| alt="{{ user.username ~' '~ 'avatar'|trans|lower }}"> | ||
| <a data-action="mouseover->mentions#user_popup mouseout->mentions#user_popup_out" data-mentions-username-param="{{ mention_url(user.username) }}" | ||
| href="{{ path('user_overview', {username: user.username}) }}"> | ||
| {% endif %} | ||
| {% if user.avatar %} | ||
| <img class="image-inline" | ||
| loading="lazy" | ||
| width="{{ width }}" height="{{ height }}" | ||
| style="max-width: {{ width }}px; max-height: {{ height }}px;" | ||
| src="{{ user.avatar.filePath ? (asset(user.avatar.filePath)|imagine_filter('avatar_thumb')) : user.avatar.sourceUrl }}" | ||
| alt="{{ user.username ~' '~ 'avatar'|trans|lower }}"> | ||
| {% else %} | ||
| {% set numericDigits = { | ||
| 'a': 15, 'b': 85, 'c': 42, 'd': 93, 'e': 27, 'f': 68, 'g': 11, 'h': 76, 'i': 33, 'j': 99, 'k': 54, 'l': 3, 'm': 60, 'n': 17, 'o': 81, 'p': 9, | ||
| 'q': 102, 'r': 48, 's': 21, 't': 72, 'u': 39, 'v': 6, 'w': 87, 'x': 30, 'y': 63, 'z': 12, 'A': 24, 'B': 90, 'C': 51, 'D': 105, 'E': 18, 'F': 66, | ||
| 'G': 0, 'H': 78, 'I': 45, 'J': 96, 'K': 57, 'L': 9, 'M': 69, 'N': 14, 'O': 84, 'P': 3, 'Q': 108, 'R': 36, 'S': 15, 'T': 75, 'U': 42, 'V': 12, | ||
| 'W': 93, 'X': 27, 'Y': 60, 'Z': 21, '0': 111, '1': 6, '2': 45, '3': 90, '4': 24, '5': 78, '6': 33, '7': 99, '8': 18, '9': 57, '_': 126, '-': 63 } %} | ||
|
|
||
| {% set validChars = '' %} | ||
| {% for char in user.username|split('') %} | ||
| {% if char in numericDigits|keys %} | ||
| {% set validChars = validChars ~ char %} | ||
| {% endif %} | ||
| {% endfor %} | ||
| {% set validChars = validChars ~ "012345" %} | ||
|
|
||
| {% set chars = validChars|slice(0, 6) %} | ||
| {% set sum = 0 %} | ||
| {% for char in chars|split('') %} | ||
| {% set sum = sum + numericDigits[char] %} | ||
| {% endfor %} | ||
|
|
||
| {% set hueRotation = (sum % 360) %} | ||
| {% set saturation = 0.4 + (sum % 60) / 100 %} {# Range: 0.4 to 1.0 #} | ||
|
|
||
| {% if app.user is defined and app.user is not same as null and app.user is same as user %} | ||
| {% set noAvatar = "you can set your avatar in your profile" %} | ||
| {% else %} | ||
| <div class="no-avatar"></div> | ||
| {% set noAvatar = user.username ~ " has no avatar" %} | ||
| {% endif %} | ||
| {% if asLink %} | ||
| </a> | ||
| <img class="image-inline" | ||
| loading="lazy" | ||
| width="{{ width }}" height="{{ height }}" | ||
| src="/default_avatar.png" | ||
| title="{{ noAvatar }}" | ||
| alt="{{ noAvatar }}" | ||
| style="max-width: {{ width }}px; max-height: {{ height }}px; filter: saturate({{ saturation }}) hue-rotate({{ hueRotation }}deg) contrast(0.9999);"> | ||
| {% endif %} | ||
| {% if asLink %} | ||
| </a> | ||
| {% endif %} | ||
| </figure> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be reduced to a single:
/.vsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is vs such a pita