From f748b99eb1eb2e4fa3f7e5bbcf4b69efc70312c9 Mon Sep 17 00:00:00 2001 From: Daniele Tonon Date: Thu, 28 Dec 2023 23:00:22 +0100 Subject: [PATCH] Show cut gradient at the text-image bottom only if necessary --- render_image.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/render_image.go b/render_image.go index b2c39f8..1cd9ee6 100644 --- a/render_image.go +++ b/render_image.go @@ -86,6 +86,7 @@ func drawImage(paragraphs []string, style Style, metadata sdk.ProfileMetadata, d height := 525 paddingLeft := 25 barExtraPadding := 0 + gradientRectHeight := 140 switch style { case StyleTelegram: paddingLeft += 10 @@ -120,13 +121,14 @@ func drawImage(paragraphs []string, style Style, metadata sdk.ProfileMetadata, d img.Fill() // a rectangle at the bottom with a gradient from black to transparent - gradientRectHeight := 140 - gradientRectY := height - barHeight - gradientRectHeight - for y := 0; y < gradientRectHeight; y++ { - alpha := uint8(255 * (math.Pow(float64(y)/float64(gradientRectHeight), 2))) - img.SetRGBA255(int(BACKGROUND.R), int(BACKGROUND.G), int(BACKGROUND.B), int(alpha)) - img.DrawRectangle(0, float64(gradientRectY+y), float64(width), 1) - img.Fill() + if len(strings.Join(paragraphs, "\n")) > 141 { + gradientRectY := height - barHeight - gradientRectHeight + for y := 0; y < gradientRectHeight; y++ { + alpha := uint8(255 * (math.Pow(float64(y)/float64(gradientRectHeight), 2))) + img.SetRGBA255(int(BACKGROUND.R), int(BACKGROUND.G), int(BACKGROUND.B), int(alpha)) + img.DrawRectangle(0, float64(gradientRectY+y), float64(width), 1) + img.Fill() + } } // draw author's name