Live video on the AT Protocol

redcircle: fix scaling math when not 1000x1000

+35 -12
+2
pkg/atproto/.gitignore
··· 1 + test.jpg 2 + test_scumbag.jpg
+10 -1
pkg/atproto/redcircle.go
··· 28 28 29 29 const BORDER_SIZE = 62.0 30 30 31 + const BorderScaleFactor = WIDTH / (WIDTH - BORDER_SIZE*2) 32 + 31 33 //go:embed redcircle.png 32 34 var RedCirclePNG []byte 33 35 ··· 45 47 return nil, fmt.Errorf("failed to decode image: %w", err) 46 48 } 47 49 48 - scaleFactor := WIDTH / (WIDTH - BORDER_SIZE*2) 50 + // profileWidth := profileImg.Bounds().Max.X 51 + 52 + scaleFactor := (float64(profileImg.Bounds().Max.X) / float64(WIDTH)) * BorderScaleFactor 53 + // scaleFactor := 1.0 54 + 55 + fmt.Println("scaleFactor", scaleFactor) 56 + 57 + // 49 58 50 59 // Draw the decoded image onto the canvas 51 60 canvasCtx := canvas.NewContext(c)
+23 -10
pkg/atproto/redcircle_test.go
··· 9 9 ) 10 10 11 11 func TestGenerateRedCircle(t *testing.T) { 12 - bs, err := os.ReadFile("robot.jpg") 13 - require.NoError(t, err) 14 - img, err := GenerateRedCircle(context.Background(), bs) 15 - require.NoError(t, err) 16 - require.NotNil(t, img) 17 - f, err := os.Create("test.jpg") 18 - require.NoError(t, err) 19 - defer f.Close() 20 - _, err = f.Write(img) 21 - require.NoError(t, err) 12 + testCases := []struct { 13 + infile string 14 + outfile string 15 + }{ 16 + {"robot.jpg", "test.jpg"}, 17 + {"scumbag.png", "test_scumbag.jpg"}, 18 + } 19 + 20 + for _, tc := range testCases { 21 + tc := tc // capture for parallel tests 22 + t.Run(tc.infile, func(t *testing.T) { 23 + bs, err := os.ReadFile(tc.infile) 24 + require.NoError(t, err) 25 + img, err := GenerateRedCircle(context.Background(), bs) 26 + require.NoError(t, err) 27 + require.NotNil(t, img) 28 + f, err := os.Create(tc.outfile) 29 + require.NoError(t, err) 30 + defer f.Close() 31 + _, err = f.Write(img) 32 + require.NoError(t, err) 33 + }) 34 + } 22 35 }
pkg/atproto/scumbag.png

This is a binary file and will not be displayed.

-1
pkg/redcircle/.gitignore
··· 1 - test.jpg