From 965833a737be72114fa2954b7f215b8dfa8eb107 Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Tue, 28 Jul 2015 17:31:27 -0700 Subject: Added godeps and the source for the go freetype library --- api/user.go | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) (limited to 'api/user.go') diff --git a/api/user.go b/api/user.go index bb7e564ae..67e459701 100644 --- a/api/user.go +++ b/api/user.go @@ -7,7 +7,6 @@ import ( "bytes" "code.google.com/p/freetype-go/freetype" l4g "code.google.com/p/log4go" - "flag" "fmt" "github.com/gorilla/mux" "github.com/mattermost/platform/model" @@ -591,12 +590,6 @@ func getAudits(c *Context, w http.ResponseWriter, r *http.Request) { } } -var ( - dpi = flag.Float64("dpi", 72, "screen resolution in Dots Per Inch") - fontfile = flag.String("fontfile", utils.FindDir("web/static/fonts")+"/luximbi.ttf", "filename of the ttf font") - size = flag.Float64("size", 62, "font size in points") -) - func createProfileImage(username string, userId string) ([]byte, *model.AppError) { colors := []color.NRGBA{ {197, 8, 126, 255}, @@ -631,26 +624,9 @@ func createProfileImage(username string, userId string) ([]byte, *model.AppError h.Write([]byte(userId)) seed := h.Sum32() - initials := "" - parts := strings.Split(username, " ") - - for _, v := range parts { - if len(v) > 0 { - initials += string(strings.ToUpper(v)[0]) - } - } - - if len(initials) == 0 { - initials = "^" - } - - if len(initials) > 2 { - initials = initials[0:2] - } - - flag.Parse() + initial := string(strings.ToUpper(username)[0]) - fontBytes, err := ioutil.ReadFile(*fontfile) + fontBytes, err := ioutil.ReadFile(utils.FindDir("web/static/fonts") + "luximbi.ttf") if err != nil { return nil, model.NewAppError("createProfileImage", "Could not create default profile image font", err.Error()) } @@ -663,17 +639,17 @@ func createProfileImage(username string, userId string) ([]byte, *model.AppError dstImg := image.NewRGBA(image.Rect(0, 0, int(utils.Cfg.ImageSettings.ProfileWidth), int(utils.Cfg.ImageSettings.ProfileHeight))) srcImg := image.White draw.Draw(dstImg, dstImg.Bounds(), &image.Uniform{color}, image.ZP, draw.Src) + size := float64(62) c := freetype.NewContext() - c.SetDPI(*dpi) c.SetFont(font) - c.SetFontSize(*size) + c.SetFontSize(size) c.SetClip(dstImg.Bounds()) c.SetDst(dstImg) c.SetSrc(srcImg) pt := freetype.Pt(int(utils.Cfg.ImageSettings.ProfileWidth)/2-45, int(utils.Cfg.ImageSettings.ProfileHeight)/2+20) - _, err = c.DrawString(initials, pt) + _, err = c.DrawString(initial, pt) if err != nil { return nil, model.NewAppError("createProfileImage", "Could not add user initial to default profile picture", err.Error()) } -- cgit v1.2.3-1-g7c22