Created
November 7, 2016 06:18
-
-
Save tommy351/ba925d01c41afa676dbd8f5be112ff98 to your computer and use it in GitHub Desktop.
This file contains 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
src, _ := loadBaseImageForPost(post) | |
img := image.NewRGBA(src.Bounds()) | |
gc := draw2dimg.NewGraphicContext(img) | |
gc.DrawImage(src) | |
// Draw title | |
gc.SetFillColor(color.RGBA{0xff, 0xff, 0xff, 0xff}) | |
gc.SetFontSize(26) | |
gc.FillStringAt(post.Title, 140, 81.5) | |
// Draw content | |
gc.SetFillColor(color.RGBA{0x32, 0x32, 0x32, 0xff}) | |
gc.SetFontSize(26) | |
gc.FillStringAt(post.Content, 60, 190) | |
// Draw forum | |
forum := post.ForumName | |
_, _, right, _ := gc.GetStringBounds(forum) | |
gc.SetFillColor(color.RGBA{0xff, 0xff, 0xff, 0xff}) | |
gc.SetFontSize(26) | |
gc.FillStringAt(forum, 1140-right, 81.5) | |
// Draw time | |
timeLocation, _ := time.LoadLocation("Asia/Taipei") | |
time := post.CreatedAt.In(timeLocation).Format("2006/1/2 15:04") | |
_, _, right, bottom := gc.GetStringBounds(time) | |
gc.SetFillColor(color.RGBA{0x79, 0x79, 0x79, 0xff}) | |
gc.SetFontSize(26) | |
gc.FillStringAt(time, 1140-right, 510-bottom) | |
ctx.Response.Header.Set("Content-Type", "image/png") | |
png.Encode(ctx, img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment