Skip to content

Make avatar size factor a configurable option #1

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

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
@@ -1587,6 +1587,9 @@ PATH =
;AVATAR_MAX_WIDTH = 4096
;AVATAR_MAX_HEIGHT = 3072
;;
;; Set the multiplication factor for requesting avatars - larger values make smoother avatars on hiDPI views
;AVATAR_RENDERED_SIZE_FACTOR=3
;;
;; Maximum allowed file size for uploaded avatars.
;; This is to limit the amount of RAM used when resizing the image.
;AVATAR_MAX_FILE_SIZE = 1048576
1 change: 1 addition & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
@@ -710,6 +710,7 @@ Define allowed algorithms and their minimum key length (use -1 to disable a type
- `AVATAR_MAX_WIDTH`: **4096**: Maximum avatar image width in pixels.
- `AVATAR_MAX_HEIGHT`: **3072**: Maximum avatar image height in pixels.
- `AVATAR_MAX_FILE_SIZE`: **1048576** (1Mb): Maximum avatar image file size in bytes.
- `AVATAR_RENDERED_SIZE_FACTOR`: **3**: Set the multiplication factor for requesting avatars - larger values make smoother avatars on hiDPI views.

- `REPOSITORY_AVATAR_STORAGE_TYPE`: **default**: Storage type defined in `[storage.xxx]`. Default is `default` which will read `[storage]` if no section `[storage]` will be a type `local`.
- `REPOSITORY_AVATAR_UPLOAD_PATH`: **data/repo-avatars**: Path to store repository avatar image files.
3 changes: 0 additions & 3 deletions models/avatars/avatar.go
Original file line number Diff line number Diff line change
@@ -21,9 +21,6 @@ import (
// DefaultAvatarPixelSize is the default size in pixels of a rendered avatar
const DefaultAvatarPixelSize = 28

// AvatarRenderedSizeFactor is the factor by which the default size is increased for finer rendering
const AvatarRenderedSizeFactor = 3

// EmailHash represents a pre-generated hash map (mainly used by LibravatarURL, it queries email server's DNS records)
type EmailHash struct {
Hash string `xorm:"pk varchar(32)"`
3 changes: 2 additions & 1 deletion modules/repository/commits.go
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
)

@@ -141,7 +142,7 @@ func (pc *PushCommits) AvatarLink(email string) string {
return avatar
}

size := avatars.DefaultAvatarPixelSize * avatars.AvatarRenderedSizeFactor
size := avatars.DefaultAvatarPixelSize * setting.Avatar.RenderedSizeFactor

u, ok := pc.emailUsers[email]
if !ok {
15 changes: 9 additions & 6 deletions modules/setting/picture.go
Original file line number Diff line number Diff line change
@@ -18,13 +18,15 @@ var (
Avatar = struct {
Storage

MaxWidth int
MaxHeight int
MaxFileSize int64
MaxWidth int
MaxHeight int
MaxFileSize int64
RenderedSizeFactor int
}{
MaxWidth: 4096,
MaxHeight: 3072,
MaxFileSize: 1048576,
MaxWidth: 4096,
MaxHeight: 3072,
MaxFileSize: 1048576,
RenderedSizeFactor: 3,
}

GravatarSource string
@@ -55,6 +57,7 @@ func newPictureService() {
Avatar.MaxWidth = sec.Key("AVATAR_MAX_WIDTH").MustInt(4096)
Avatar.MaxHeight = sec.Key("AVATAR_MAX_HEIGHT").MustInt(3072)
Avatar.MaxFileSize = sec.Key("AVATAR_MAX_FILE_SIZE").MustInt64(1048576)
Avatar.RenderedSizeFactor = sec.Key("AVATAR_RENDERED_SIZE_FACTOR").MustInt(3)

switch source := sec.Key("GRAVATAR_SOURCE").MustString("gravatar"); source {
case "duoshuo":
8 changes: 4 additions & 4 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
@@ -557,17 +557,17 @@ func Avatar(item interface{}, others ...interface{}) template.HTML {

switch t := item.(type) {
case *user_model.User:
src := t.AvatarLinkWithSize(size * avatars.AvatarRenderedSizeFactor)
src := t.AvatarLinkWithSize(size * setting.Avatar.RenderedSizeFactor)
if src != "" {
return AvatarHTML(src, size, class, t.DisplayName())
}
case *models.Collaborator:
src := t.AvatarLinkWithSize(size * avatars.AvatarRenderedSizeFactor)
src := t.AvatarLinkWithSize(size * setting.Avatar.RenderedSizeFactor)
if src != "" {
return AvatarHTML(src, size, class, t.DisplayName())
}
case *models.Organization:
src := t.AsUser().AvatarLinkWithSize(size * avatars.AvatarRenderedSizeFactor)
src := t.AsUser().AvatarLinkWithSize(size * setting.Avatar.RenderedSizeFactor)
if src != "" {
return AvatarHTML(src, size, class, t.AsUser().DisplayName())
}
@@ -596,7 +596,7 @@ func RepoAvatar(repo *repo_model.Repository, others ...interface{}) template.HTM
// AvatarByEmail renders avatars by email address. args: email, name, size (int), class (string)
func AvatarByEmail(email string, name string, others ...interface{}) template.HTML {
size, class := parseOthers(avatars.DefaultAvatarPixelSize, "ui avatar image", others...)
src := avatars.GenerateEmailAvatarFastLink(email, size*avatars.AvatarRenderedSizeFactor)
src := avatars.GenerateEmailAvatarFastLink(email, size*setting.Avatar.RenderedSizeFactor)

if src != "" {
return AvatarHTML(src, size, class, name)