Show cut gradient at the text-image bottom only if necessary

This commit is contained in:
Daniele Tonon
2023-12-28 23:00:22 +01:00
parent 89ed30c1ec
commit f748b99eb1

View File

@@ -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,7 +121,7 @@ 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
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)))
@@ -128,6 +129,7 @@ func drawImage(paragraphs []string, style Style, metadata sdk.ProfileMetadata, d
img.DrawRectangle(0, float64(gradientRectY+y), float64(width), 1)
img.Fill()
}
}
// draw author's name
authorTextX := paddingLeft + barExtraPadding