tangled
alpha
login
or
join now
margin.at
/
margin
86
fork
atom
Write on the margins of the internet. Powered by the AT Protocol.
margin.at
extension
web
atproto
comments
86
fork
atom
overview
issues
4
pulls
1
pipelines
better looks for annotation/bookmark OG images
scanash.com
2 months ago
14adba53
5eae943d
+25
-37
1 changed file
expand all
collapse all
unified
split
backend
internal
api
og.go
+25
-37
backend/internal/api/og.go
···
793
793
func generateOGImagePNG(author, text, quote, source, avatarURL string) image.Image {
794
794
width := 1200
795
795
height := 630
796
796
-
padding := 120
796
796
+
padding := 100
797
797
798
798
bgPrimary := color.RGBA{12, 10, 20, 255}
799
799
accent := color.RGBA{168, 85, 247, 255}
800
800
textPrimary := color.RGBA{244, 240, 255, 255}
801
801
textSecondary := color.RGBA{168, 158, 200, 255}
802
802
-
textTertiary := color.RGBA{107, 95, 138, 255}
803
802
border := color.RGBA{45, 38, 64, 255}
804
803
805
804
img := image.NewRGBA(image.Rect(0, 0, width, height))
806
805
807
806
draw.Draw(img, img.Bounds(), &image.Uniform{bgPrimary}, image.Point{}, draw.Src)
808
808
-
draw.Draw(img, image.Rect(0, 0, width, 6), &image.Uniform{accent}, image.Point{}, draw.Src)
807
807
+
draw.Draw(img, image.Rect(0, 0, width, 12), &image.Uniform{accent}, image.Point{}, draw.Src)
809
808
810
810
-
if logoImage != nil {
811
811
-
logoHeight := 50
812
812
-
logoWidth := int(float64(logoImage.Bounds().Dx()) * (float64(logoHeight) / float64(logoImage.Bounds().Dy())))
813
813
-
drawScaledImage(img, logoImage, padding, 80, logoWidth, logoHeight)
814
814
-
} else {
815
815
-
drawText(img, "Margin", padding, 120, accent, 36, true)
816
816
-
}
809
809
+
avatarSize := 64
810
810
+
avatarX := padding
811
811
+
avatarY := padding
817
812
818
818
-
avatarSize := 80
819
819
-
avatarX := padding
820
820
-
avatarY := 180
821
813
avatarImg := fetchAvatarImage(avatarURL)
822
814
if avatarImg != nil {
823
815
drawCircularAvatar(img, avatarImg, avatarX, avatarY, avatarSize)
824
816
} else {
825
817
drawDefaultAvatar(img, author, avatarX, avatarY, avatarSize, accent)
826
818
}
827
827
-
828
828
-
handleX := avatarX + avatarSize + 24
829
829
-
drawText(img, author, handleX, avatarY+50, textSecondary, 24, false)
830
830
-
831
831
-
yPos := 280
832
832
-
draw.Draw(img, image.Rect(padding, yPos, width-padding, yPos+1), &image.Uniform{border}, image.Point{}, draw.Src)
833
833
-
yPos += 40
819
819
+
drawText(img, author, avatarX+avatarSize+24, avatarY+42, textSecondary, 28, false)
834
820
835
821
contentWidth := width - (padding * 2)
822
822
+
yPos := 220
836
823
837
824
if text != "" {
838
825
textLen := len(text)
839
839
-
textSize := 32
826
826
+
textSize := 32.0
840
827
textLineHeight := 42
841
841
-
maxTextLines := 6
828
828
+
maxTextLines := 5
842
829
843
830
if textLen > 200 {
844
844
-
textSize = 28
831
831
+
textSize = 28.0
845
832
textLineHeight = 36
846
846
-
maxTextLines = 7
833
833
+
maxTextLines = 6
847
834
}
848
835
849
849
-
lines := wrapTextToWidth(text, contentWidth, textSize)
836
836
+
lines := wrapTextToWidth(text, contentWidth, int(textSize))
850
837
numLines := min(len(lines), maxTextLines)
851
838
852
839
for i := 0; i < numLines; i++ {
···
854
841
if i == numLines-1 && len(lines) > numLines {
855
842
line += "..."
856
843
}
857
857
-
drawText(img, line, padding, yPos+(i*textLineHeight), textPrimary, float64(textSize), false)
844
844
+
drawText(img, line, padding, yPos+(i*textLineHeight), textPrimary, textSize, false)
858
845
}
859
846
yPos += (numLines * textLineHeight) + 40
860
847
}
861
848
862
849
if quote != "" {
863
850
quoteLen := len(quote)
864
864
-
quoteSize := 24
851
851
+
quoteSize := 24.0
865
852
quoteLineHeight := 32
866
866
-
maxQuoteLines := 2
853
853
+
maxQuoteLines := 3
867
854
868
855
if quoteLen > 150 {
869
869
-
quoteSize = 20
856
856
+
quoteSize = 20.0
870
857
quoteLineHeight = 28
871
871
-
maxQuoteLines = 3
858
858
+
maxQuoteLines = 4
872
859
}
873
860
874
874
-
lines := wrapTextToWidth(quote, contentWidth-30, quoteSize)
861
861
+
lines := wrapTextToWidth(quote, contentWidth-30, int(quoteSize))
875
862
numLines := min(len(lines), maxQuoteLines)
876
876
-
barHeight := numLines*quoteLineHeight + 10
863
863
+
barHeight := numLines * quoteLineHeight
877
864
878
865
draw.Draw(img, image.Rect(padding, yPos, padding+6, yPos+barHeight), &image.Uniform{accent}, image.Point{}, draw.Src)
879
866
880
867
for i := 0; i < numLines; i++ {
881
868
line := lines[i]
882
882
-
isLast := i == numLines-1
883
883
-
if isLast && len(lines) > numLines {
869
869
+
if i == numLines-1 && len(lines) > numLines {
884
870
line += "..."
885
871
}
886
886
-
drawText(img, "\""+line+"\"", padding+24, yPos+28+(i*quoteLineHeight), textTertiary, float64(quoteSize), true)
872
872
+
drawText(img, line, padding+24, yPos+24+(i*quoteLineHeight), textSecondary, quoteSize, true)
887
873
}
888
888
-
yPos += 30 + (numLines * quoteLineHeight) + 30
874
874
+
yPos += barHeight + 40
889
875
}
890
876
891
891
-
drawText(img, source, padding, 580, textTertiary, 20, false)
877
877
+
draw.Draw(img, image.Rect(padding, yPos, width-padding, yPos+1), &image.Uniform{border}, image.Point{}, draw.Src)
878
878
+
yPos += 40
879
879
+
drawText(img, source, padding, yPos+32, textSecondary, 24, false)
892
880
893
881
return img
894
882
}