-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add more random Avatar generators (DiceBear, Robot) and make it configurable #17701
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ece85d8
add new dep
6543 124e00e
split rand-avatar-generators into own packages
6543 0a57edd
Merge branch 'master' into rand-avatar-changable
6543 dfd0063
nit
6543 12afae7
make it posible to behave different for users/orgs/repos
6543 f98b993
Merge branch 'master' into rand-avatar-changable
6543 414387d
tag dicebear
6543 aec10e1
nit
6543 951fba9
infent fancy interfaces
6543 dda44fd
add robot
6543 7750878
use only one lib to convert svg to png
6543 f09578d
Merge branch 'master' into rand-avatar-changable
6543 0a0b147
fix lint
6543 309c5e1
add monsterid
6543 8c6bed3
add wavatars
6543 47a7734
Revert "add wavatars"
6543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dice_bear | ||
|
||
import ( | ||
"image" | ||
"strings" | ||
|
||
"codeberg.org/Codeberg/avatars" | ||
"github.com/srwiley/oksvg" | ||
"github.com/srwiley/rasterx" | ||
) | ||
|
||
func RandomImageSize(size int, data []byte) (image.Image, error) { | ||
avatar := avatars.MakeAvatar(string(data)) | ||
return svg2image(avatar, size, size) | ||
} | ||
|
||
func svg2image(svg string, width, height int) (image.Image, error) { | ||
icon, err := oksvg.ReadIconStream(strings.NewReader(svg)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
icon.SetTarget(0, 0, float64(width), float64(height)) | ||
rgba := image.NewRGBA(image.Rect(0, 0, width, height)) | ||
icon.Draw(rasterx.NewDasher(width, height, rasterx.NewScannerGV(width, height, rgba, rgba.Bounds())), 1) | ||
|
||
return rgba, nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package identicon | ||
|
||
import ( | ||
"fmt" | ||
"image" | ||
"image/color/palette" | ||
|
||
"code.gitea.io/gitea/modules/util" | ||
|
||
"github.com/issue9/identicon" | ||
) | ||
|
||
// RandomImageSize generates and returns a random avatar image unique to input data | ||
// in custom size (height and width). | ||
func RandomImageSize(size int, data []byte) (image.Image, error) { | ||
randExtent := len(palette.WebSafe) - 32 | ||
integer, err := util.RandomInt(int64(randExtent)) | ||
if err != nil { | ||
return nil, fmt.Errorf("util.RandomInt: %v", err) | ||
} | ||
colorIndex := int(integer) | ||
backColorIndex := colorIndex - 1 | ||
if backColorIndex < 0 { | ||
backColorIndex = randExtent - 1 | ||
} | ||
|
||
// Define size, background, and forecolor | ||
imgMaker, err := identicon.New(size, | ||
palette.WebSafe[backColorIndex], palette.WebSafe[colorIndex:colorIndex+32]...) | ||
if err != nil { | ||
return nil, fmt.Errorf("identicon.New: %v", err) | ||
} | ||
return imgMaker.Make(data), nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.