summaryrefslogtreecommitdiffstats
path: root/app/user.go
diff options
context:
space:
mode:
authorAsaad Mahmood <asaadmahmood@users.noreply.github.com>2018-07-05 12:18:26 +0500
committerCarlos Tadeu Panato Junior <ctadeu@gmail.com>2018-07-05 09:18:26 +0200
commit8d3ea1bbf6f6ef6164d26b6801c46cfe7f936fa1 (patch)
treec115a11998979a9592ee495841624f1ebff80f0c /app/user.go
parent6b7a35b653cbb3fdcd27a542c8a7faec4352d153 (diff)
downloadchat-8d3ea1bbf6f6ef6164d26b6801c46cfe7f936fa1.tar.gz
chat-8d3ea1bbf6f6ef6164d26b6801c46cfe7f936fa1.tar.bz2
chat-8d3ea1bbf6f6ef6164d26b6801c46cfe7f936fa1.zip
MM-10766 - Replacing default profile image font (#8955)
* Updating default profile pic font * Updating profile image font * Updating test * Use new default font if configured for old one * Update OFL.txt
Diffstat (limited to 'app/user.go')
-rw-r--r--app/user.go25
1 files changed, 18 insertions, 7 deletions
diff --git a/app/user.go b/app/user.go
index b00ef19ef..acd3ee9aa 100644
--- a/app/user.go
+++ b/app/user.go
@@ -24,6 +24,7 @@ import (
"github.com/disintegration/imaging"
"github.com/golang/freetype"
+ "github.com/golang/freetype/truetype"
"github.com/mattermost/mattermost-server/einterfaces"
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
@@ -696,12 +697,7 @@ func CreateProfileImage(username string, userId string, initialFont string) ([]b
initial := string(strings.ToUpper(username)[0])
- fontDir, _ := utils.FindDir("fonts")
- fontBytes, err := ioutil.ReadFile(filepath.Join(fontDir, initialFont))
- if err != nil {
- return nil, model.NewAppError("CreateProfileImage", "api.user.create_profile_image.default_font.app_error", nil, err.Error(), http.StatusInternalServerError)
- }
- font, err := freetype.ParseFont(fontBytes)
+ font, err := getFont(initialFont)
if err != nil {
return nil, model.NewAppError("CreateProfileImage", "api.user.create_profile_image.default_font.app_error", nil, err.Error(), http.StatusInternalServerError)
}
@@ -719,7 +715,7 @@ func CreateProfileImage(username string, userId string, initialFont string) ([]b
c.SetDst(dstImg)
c.SetSrc(srcImg)
- pt := freetype.Pt(IMAGE_PROFILE_PIXEL_DIMENSION/6, IMAGE_PROFILE_PIXEL_DIMENSION*2/3)
+ pt := freetype.Pt(IMAGE_PROFILE_PIXEL_DIMENSION/5, IMAGE_PROFILE_PIXEL_DIMENSION*2/3)
_, err = c.DrawString(initial, pt)
if err != nil {
return nil, model.NewAppError("CreateProfileImage", "api.user.create_profile_image.initial.app_error", nil, err.Error(), http.StatusInternalServerError)
@@ -734,6 +730,21 @@ func CreateProfileImage(username string, userId string, initialFont string) ([]b
}
}
+func getFont(initialFont string) (*truetype.Font, error) {
+ // Some people have the old default font still set, so just treat that as if they're using the new default
+ if initialFont == "luximbi.ttf" {
+ initialFont = "nunito-bold.ttf"
+ }
+
+ fontDir, _ := utils.FindDir("fonts")
+ fontBytes, err := ioutil.ReadFile(filepath.Join(fontDir, initialFont))
+ if err != nil {
+ return nil, err
+ }
+
+ return freetype.ParseFont(fontBytes)
+}
+
func (a *App) GetProfileImage(user *model.User) ([]byte, bool, *model.AppError) {
var img []byte
readFailed := false