@@ -102,7 +102,7 @@ func drawImage(paragraphs []string, style Style, metadata sdk.ProfileMetadata, d
102
102
img .SetColor (FOREGROUND )
103
103
104
104
// main content text
105
- textImg := drawText (paragraphs , width - paddingLeft * 2 , height - 20 )
105
+ textImg := drawText (paragraphs , width - paddingLeft * 2 , height - 20 , true )
106
106
img .DrawImage (textImg , paddingLeft , 20 )
107
107
108
108
// font for writing the bottom bar stuff
@@ -144,7 +144,7 @@ func drawImage(paragraphs []string, style Style, metadata sdk.ProfileMetadata, d
144
144
authorTextY := height - barHeight + 15
145
145
authorMaxWidth := width / 2.0 - paddingLeft * 2 - barExtraPadding
146
146
img .SetColor (color .White )
147
- textImg = drawText ([]string {metadata .ShortName ()}, width , barHeight )
147
+ textImg = drawText ([]string {metadata .ShortName ()}, width , barHeight , false )
148
148
img .DrawImage (textImg , authorTextX , authorTextY )
149
149
150
150
// a gradient to cover too long names
@@ -177,11 +177,36 @@ func drawImage(paragraphs []string, style Style, metadata sdk.ProfileMetadata, d
177
177
return img .Image (), nil
178
178
}
179
179
180
- func drawText (paragraphs []string , width , height int ) image.Image {
181
- const FONT_SIZE = 25
180
+ func drawText (paragraphs []string , width , height int , dynamicResize bool ) image.Image {
181
+ FONT_SIZE : = 25
182
182
color := color.RGBA {R : 255 , G : 230 , B : 238 , A : 255 }
183
183
img := image .NewNRGBA (image .Rect (0 , 0 , width , height ))
184
184
185
+ joinedContent := strings .Join (paragraphs , "\n " )
186
+ if dynamicResize && len (joinedContent ) < 141 {
187
+ FONT_SIZE = 7
188
+ img := gg .NewContext (width , height )
189
+ fontData , _ := fonts .ReadFile ("fonts/NotoSans.ttf" )
190
+ ttf , _ := truetype .Parse (fontData )
191
+ i := 1
192
+ lineSpacing := 1.2
193
+ for i < 20 {
194
+ FONT_SIZE += i
195
+ img .SetFontFace (truetype .NewFace (ttf , & truetype.Options {
196
+ Size : float64 (FONT_SIZE ),
197
+ DPI : 260 ,
198
+ }))
199
+ wrappedContent := strings .Join (img .WordWrap (joinedContent , float64 (width - 120 )), "\n " )
200
+ _ , checkHeight := img .MeasureMultilineString (wrappedContent , lineSpacing )
201
+ if checkHeight > float64 (height - 70 - 60 * 2 ) {
202
+ FONT_SIZE -= 1
203
+ break
204
+ }
205
+ i += 1
206
+ }
207
+ FONT_SIZE = FONT_SIZE * 4 - 2
208
+ }
209
+
185
210
lineNumber := 1
186
211
for _ , paragraph := range paragraphs {
187
212
rawText := []rune (paragraph )
0 commit comments